ZQuest Classic Coverage Report


Directory: src/
File: src/zc/ffscript.cpp
Date: 2025-07-11 05:52:07
Exec Total Coverage
Lines: 6666 20704 32.2%
Functions: 446 974 45.8%
Branches: 3765 16345 23.0%

Line Branch Exec Source
1 #include <cstdint>
2 #include <deque>
3 #include <string>
4 #include <sstream>
5 #include <math.h>
6 #include <cstdio>
7 #include <algorithm>
8 #include <ranges>
9 //
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <fstream>
15 #include <filesystem>
16 #include <fmt/format.h>
17 #include <fmt/ranges.h>
18 //
19
20 #include "base/check.h"
21 #include "base/expected.h"
22 #include "base/handles.h"
23 #include "base/general.h"
24 #include "base/mapscr.h"
25 #include "base/qrs.h"
26 #include "base/dmap.h"
27 #include "base/msgstr.h"
28 #include "base/packfile.h"
29 #include "base/misctypes.h"
30 #include "base/initdata.h"
31 #include "base/version.h"
32 #include "new_subscr.h"
33 #include "zc/maps.h"
34 #include "zasm/serialize.h"
35 #include "zasm/table.h"
36 #include "zc/replay.h"
37 #include "zc/scripting/arrays.h"
38 #include "zc/scripting/script_object.h"
39 #include "zc/scripting/types.h"
40 #include "zc/scripting/types/websocket.h"
41 #include "zc/zasm_optimize.h"
42 #include "zc/zasm_utils.h"
43 #include "zc/zc_ffc.h"
44 #include "zc/zc_sys.h"
45 #include "zc/jit.h"
46 #include "zc/script_debug.h"
47 #include "base/zc_alleg.h"
48 #include "base/zc_math.h"
49 #include "base/zc_array.h"
50 #include "zc/ffscript.h"
51 #include "zc/render.h"
52 #include "zc/zc_subscr.h"
53 #include <time.h>
54 #include "zc/script_drawing.h"
55 #include "base/util.h"
56 #include "zc/ending.h"
57 #include "zc/combos.h"
58 #include "drawing.h"
59 #include "base/colors.h"
60 #include "pal.h"
61 #include "zinfo.h"
62 #include "subscr.h"
63 #include "zc_list_data.h"
64 #include "music_playback.h"
65 #include "iter.h"
66 #include <sstream>
67
68 #include "zc/zelda.h"
69 #include "particles.h"
70 #include "zc/hero.h"
71 #include "zc/guys.h"
72 #include "gamedata.h"
73 #include "zc/zc_init.h"
74 #include "base/zsys.h"
75 #include "base/misctypes.h"
76 #include "zc/title.h"
77 #include "zscriptversion.h"
78
79 #include "pal.h"
80 #include "base/zdefs.h"
81 #include "zc/rendertarget.h"
82
83 #include "hero_tiles.h"
84 #include "base/qst.h"
85
86 using namespace util;
87
88 #ifdef _WIN32
89 #define SCRIPT_FILE_MODE (_S_IREAD | _S_IWRITE)
90 #else
91 #include <fcntl.h>
92 #include <unistd.h>
93 #include <iostream>
94 #define SCRIPT_FILE_MODE (S_ISVTX | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
95 #endif
96
97 //Define this register, so it can be treated specially
98 #define NUL 5
99 #define MAX_ZC_ARRAY_SIZE 214748
100
101 using namespace util;
102 using std::ostringstream;
103
104 static ASM_DEFINE current_zasm_command;
105 static uint32_t current_zasm_register;
106 // If set, the next call to scripting_log_error_with_context will use this string in addition to whatever
107 // current_zasm_command and current_zasm_register refer to. Must unset after manually.
108 std::string current_zasm_extra_context;
109 // If set, the next call to scripting_log_error_with_context will use this string instead of whatever
110 // current_zasm_command and current_zasm_register refer to. Must unset after manually.
111 std::string current_zasm_context;
112
113 2037981 void scripting_log_error_with_context(std::string text)
114 {
115
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2037981 times.
2037981 if (current_zasm_context.empty())
116 {
117 2037981 std::vector<const char*> context;
118
119
1/2
✓ Branch 0 taken 2037981 times.
✗ Branch 1 not taken.
2037981 const char* register_string = scripting_get_zasm_register_context_string(current_zasm_register);
120
2/2
✓ Branch 0 taken 1007460 times.
✓ Branch 1 taken 1030521 times.
2037981 if (register_string)
121
1/2
✓ Branch 0 taken 1007460 times.
✗ Branch 1 not taken.
1007460 context.push_back(register_string);
122
123
1/2
✓ Branch 0 taken 2037981 times.
✗ Branch 1 not taken.
2037981 const char* command_string = scripting_get_zasm_command_context_string(current_zasm_command);
124
2/2
✓ Branch 0 taken 1835972 times.
✓ Branch 1 taken 202009 times.
2037981 if (command_string)
125
1/2
✓ Branch 0 taken 1835972 times.
✗ Branch 1 not taken.
1835972 context.push_back(command_string);
126
127
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2037977 times.
2037981 if (!current_zasm_extra_context.empty())
128
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 context.push_back(current_zasm_extra_context.c_str());
129
130
2/2
✓ Branch 0 taken 2028011 times.
✓ Branch 1 taken 9970 times.
2037981 if (context.size())
131
3/6
✓ Branch 0 taken 2028011 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2028011 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2028011 times.
✗ Branch 5 not taken.
2028011 current_zasm_context = fmt::format("{}", fmt::join(context, ", "));
132 else
133 {
134
1/2
✓ Branch 0 taken 9970 times.
✗ Branch 1 not taken.
9970 Z_scripterrlog("%s\n", text.c_str());
135 9970 return;
136 }
137
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 9970 times.
✓ Branch 2 taken 2028011 times.
2037981 }
138
139 2028011 Z_scripterrlog("%s | %s\n", current_zasm_context.c_str(), text.c_str());
140 2028011 current_zasm_context = "";
141 2028011 current_zasm_extra_context = "";
142 2037981 }
143
144 // (type, index) => ScriptEngineData
145 407 std::map<std::pair<ScriptType, int>, ScriptEngineData> scriptEngineDatas;
146
147 extern byte use_dwm_flush;
148 uint8_t using_SRAM = 0;
149
150 int32_t hangcount = 0;
151 bool can_neg_array = true;
152
153 extern byte monochrome_console;
154
155 407 static std::map<script_id, ScriptDebugHandle> script_debug_handles;
156 ScriptDebugHandle* runtime_script_debug_handle;
157 // Values may be null.
158 407 static std::map<std::pair<script_data*, refInfo*>, JittedScriptHandle*> jitted_scripts;
159 int32_t jitted_uncompiled_command_count;
160
161 407 CScriptDrawingCommands scriptdraws;
162 407 FFScript FFCore;
163
164 static expected<std::string, std::string> parse_user_path(const std::string& user_path, bool is_file);
165
166 static UserDataContainer<script_array, 1000000> script_arrays = {script_object_type::array, "array"};
167 static UserDataContainer<user_dir, MAX_USER_DIRS> user_dirs = {script_object_type::dir, "directory"};
168 static UserDataContainer<user_file, MAX_USER_FILES> user_files = {script_object_type::file, "file"};
169 static UserDataContainer<user_paldata, MAX_USER_PALDATAS> user_paldatas = {script_object_type::paldata, "paldata"};
170 static UserDataContainer<user_rng, MAX_USER_RNGS> user_rngs = {script_object_type::rng, "rng"};
171 static UserDataContainer<user_stack, MAX_USER_STACKS> user_stacks = {script_object_type::stack, "stack"};
172 static UserDataContainer<user_bitmap, MAX_USER_BITMAPS> user_bitmaps = {script_object_type::bitmap, "bitmap"};
173
174 210 script_array* create_script_array()
175 {
176 210 return script_arrays.create();
177 }
178
179 132 void register_existing_script_array(script_array* array)
180 {
181 132 script_arrays.register_existing(array);
182 132 }
183
184 58 std::vector<script_array*> get_script_arrays()
185 {
186 58 std::vector<script_array*> result;
187
3/4
✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 58 times.
✓ Branch 3 taken 146 times.
204 for (auto id : script_object_ids_by_type[script_arrays.type])
188 {
189
2/4
✓ Branch 0 taken 146 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 146 times.
✗ Branch 3 not taken.
146 result.push_back(&script_arrays[id]);
190 }
191 58 return result;
192
1/2
✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
58 }
193
194 26 static script_array* find_or_create_internal_script_array(script_array::internal_array_id internal_id)
195 {
196
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (!zasm_array_supports(internal_id.zasm_var))
197 {
198 scripting_log_error_with_context("Invalid internal array id: {}", internal_id.zasm_var);
199 return nullptr;
200 }
201
202
2/2
✓ Branch 0 taken 830 times.
✓ Branch 1 taken 10 times.
840 for (auto id : script_object_ids_by_type[script_arrays.type])
203 {
204 830 auto object = static_cast<script_array*>(get_script_object_checked(id));
205
5/6
✓ Branch 0 taken 830 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
✓ Branch 3 taken 796 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 16 times.
830 if (!object->internal_expired && object->internal_id.has_value() && object->internal_id.value() == internal_id)
206 16 return object;
207 }
208
209 10 auto array = script_arrays.create();
210
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (array)
211 {
212 10 array->arr.setValid(true);
213 10 array->internal_id = internal_id;
214 10 }
215 10 return array;
216 26 }
217
218 2279926 static void expire_internal_script_arrays(ScriptType scriptType, int ref)
219 {
220
2/2
✓ Branch 0 taken 920721 times.
✓ Branch 1 taken 1359205 times.
2279926 if (!ZScriptVersion::gc_arrays())
221 1359205 return;
222
223 // Expire internal arrays referring to this script object.
224
2/2
✓ Branch 0 taken 920721 times.
✓ Branch 1 taken 213801 times.
1134522 for (auto& script_object : script_objects | std::views::values)
225 {
226
2/2
✓ Branch 0 taken 753 times.
✓ Branch 1 taken 213048 times.
213801 if (script_object->type != script_object_type::array)
227 753 continue;
228
229 213048 auto array = static_cast<script_array*>(script_object.get());
230
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 213040 times.
213048 if (!array->internal_id.has_value())
231 213040 continue;
232
233
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 if (array->internal_id->matches(scriptType, ref))
234 2 array->internal_expired = true;
235 }
236 2279926 }
237
238 35190 static void expire_internal_script_arrays(ScriptType scriptType)
239 {
240
2/2
✓ Branch 0 taken 16784 times.
✓ Branch 1 taken 18406 times.
35190 if (!ZScriptVersion::gc_arrays())
241 18406 return;
242
243 // Expire internal arrays referring to this script object.
244
2/2
✓ Branch 0 taken 16784 times.
✓ Branch 1 taken 4085 times.
20869 for (auto& script_object : script_objects | std::views::values)
245 {
246
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 4025 times.
4085 if (script_object->type != script_object_type::array)
247 60 continue;
248
249 4025 auto array = static_cast<script_array*>(script_object.get());
250
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4025 times.
4025 if (!array->internal_id.has_value())
251 4025 continue;
252
253 if (array->internal_id->matches(scriptType))
254 array->internal_expired = true;
255 }
256 35190 }
257
258 65502895 script_array* checkArray(uint32_t id, bool skipError)
259 {
260 65502895 return script_arrays.check(id, skipError);
261 }
262
263 15938371 void script_bitmaps::update()
264 {
265 15938371 auto ids = script_object_ids_by_type[user_bitmaps.type];
266
2/2
✓ Branch 0 taken 35976099 times.
✓ Branch 1 taken 15938371 times.
51914470 for (auto id : ids)
267 {
268
1/2
✓ Branch 0 taken 35976099 times.
✗ Branch 1 not taken.
35976099 auto& bitmap = user_bitmaps[id];
269
3/4
✓ Branch 0 taken 35976099 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3656 times.
✓ Branch 3 taken 35972443 times.
35976099 if (bitmap.is_freeing())
270 {
271
1/2
✓ Branch 0 taken 3656 times.
✗ Branch 1 not taken.
3656 bitmap.mark_can_del();
272
1/2
✓ Branch 0 taken 3656 times.
✗ Branch 1 not taken.
3656 delete_script_object(id);
273 3656 }
274 }
275 15938371 }
276
277 320322 user_bitmap& script_bitmaps::get(int32_t id)
278 {
279
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 320316 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
320322 static user_bitmap fake;
280
281 320322 current_zasm_context = "script drawing";
282
1/2
✓ Branch 0 taken 320322 times.
✗ Branch 1 not taken.
320322 if (auto bitmap = user_bitmaps.check(id))
283 {
284 320322 current_zasm_context = "";
285 320322 return *bitmap;
286 }
287
288 return fake;
289 320322 }
290
291 script_bitmaps scb;
292 407 user_rng nulrng;
293 407 zc_randgen script_rnggens[MAX_USER_RNGS];
294
295 FONT *get_zc_font(int index);
296
297 int32_t combopos_modified = -1;
298 static std::vector<word> combo_id_cache;
299
300 void user_dir::setPath(const char* buf)
301 {
302 if(!list)
303 {
304 list = (FLIST *) calloc(1, sizeof(FLIST));
305 }
306 filepath = std::string(buf) + "/";
307 regulate_path(filepath);
308 list->load(filepath.c_str());
309 }
310
311 int32_t CScriptDrawingCommands::GetCount()
312 {
313 al_trace("current number of draws is: %d\n", count);
314 return count;
315 }
316
317 // Decodes a `mapref` (reference number) for a temporary screen.
318 //
319 // A mapref can refer to:
320 //
321 // - the canonical mapscr data, loaded via `Game->LoadMapData(int map, int screen)`
322 // - a temporary mapscr, loaded via `Game->LoadTempScreen(int layer, int? screen)`
323 // - a temporary mapscr, loaded via `Game->LoadScrollingScreen(int layer, int? screen)`
324 //
325 // The canonical maprefs are >=0, and temporary ones are all negative.
326 //
327 // If temporary, and loaded without specifiying a screen index, we allow combo array variables (like
328 // `ComboX[pos]`) to address any rpos in the region. Otherwise, only positions in the exact screen
329 // referenced by `mapref` can be used (0-175). See ResolveMapdataPos.
330 88395864 mapdata decode_mapdata_ref(int ref)
331 {
332
2/2
✓ Branch 0 taken 19036714 times.
✓ Branch 1 taken 69359150 times.
88395864 if (ref >= 0)
333 {
334
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19036714 times.
19036714 if (ref >= TheMaps.size())
335 return mapdata{};
336
337 19036714 int screen = ref % MAPSCRS;
338 19036714 return mapdata{mapdata_type::CanonicalScreen, &TheMaps[ref], screen, 0};
339 }
340
341 // Negative values are for temporary screens.
342
343 69359150 ref = -(ref + 1);
344 69359150 bool is_scrolling = ref & 1;
345 69359150 bool is_region = ref & 2;
346 69359150 int screen = (ref & 0x0000FF00) >> 8;
347 69359150 int layer = (ref & 0x00FF0000) >> 16;
348
349
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69359150 times.
69359150 if (is_region)
350 {
351
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69359150 times.
69359150 if (is_scrolling)
352 screen = scrolling_region.origin_screen;
353 else
354 69359150 screen = cur_screen;
355 69359150 }
356
357 69359150 mapscr* scr = nullptr;
358
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69359150 times.
69359150 if (is_scrolling)
359 {
360 int index = screen * 7 + layer;
361 if (index >= 0 && index < FFCore.ScrollingScreensAll.size())
362 scr = FFCore.ScrollingScreensAll[index];
363 }
364 else
365 {
366
3/6
✓ Branch 0 taken 69359150 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69359150 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 69359150 times.
69359150 if (layer >= 0 && layer <= 6 && is_in_current_region(screen))
367 69359150 scr = get_scr_layer(screen, layer);
368 }
369
370
1/2
✓ Branch 0 taken 69359150 times.
✗ Branch 1 not taken.
69359150 if (!scr)
371 return mapdata{};
372
373 69359150 auto type = mapdata_type::None;
374
2/4
✓ Branch 0 taken 69359150 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69359150 times.
✗ Branch 3 not taken.
69359150 if (is_region && is_scrolling)
375 type = mapdata_type::TemporaryScrollingRegion;
376
2/4
✓ Branch 0 taken 69359150 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 69359150 times.
69359150 else if (is_region && !is_scrolling)
377 69359150 type = mapdata_type::TemporaryCurrentRegion;
378 else if (!is_region && is_scrolling)
379 type = mapdata_type::TemporaryScrollingScreen;
380 else if (!is_region && !is_scrolling)
381 type = mapdata_type::TemporaryCurrentScreen;
382
383 69359150 return mapdata{type, scr, screen, layer};
384 88395864 }
385
386 3387223 static int create_mapdata_temp_ref(mapdata_type type, int screen, int layer)
387 {
388
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3387223 times.
3387223 bool is_scrolling = type == mapdata_type::TemporaryScrollingScreen || type == mapdata_type::TemporaryScrollingRegion;
389
2/2
✓ Branch 0 taken 177544 times.
✓ Branch 1 taken 3209679 times.
3387223 bool is_region = type == mapdata_type::TemporaryScrollingRegion || type == mapdata_type::TemporaryCurrentRegion;
390
391 3387223 int ref = 0;
392 3387223 ref |= is_scrolling ? 1 : 0;
393 3387223 ref |= is_region ? 2 : 0;
394
1/2
✓ Branch 0 taken 3387223 times.
✗ Branch 1 not taken.
3387223 if (!is_region)
395 ref |= ((screen & 0xFF) << 8);
396 3387223 ref |= ((layer & 0xFF) << 16);
397 3387223 return -ref-1;
398 }
399
400 mapscr* GetScrollingMapscr(int layer, int x, int y)
401 {
402 if (!screenscrolling)
403 return nullptr;
404
405 int screen = scrolling_region.origin_screen + map_scr_xy_to_index(x / 256, y / 176);
406 mapscr* m = FFCore.ScrollingScreensAll[screen * 7 + layer];
407 if (!m || !m->is_valid())
408 return nullptr;
409
410 return m;
411 }
412
413 9 int32_t getMap(int32_t ref)
414 {
415
1/15
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
9 switch(ref)
416 {
417 case MAPSCR_TEMP0:
418 return cur_map+1;
419 case MAPSCR_TEMP1:
420 return origin_scr->layermap[0];
421 case MAPSCR_TEMP2:
422 return origin_scr->layermap[1];
423 case MAPSCR_TEMP3:
424 return origin_scr->layermap[2];
425 case MAPSCR_TEMP4:
426 return origin_scr->layermap[3];
427 case MAPSCR_TEMP5:
428 return origin_scr->layermap[4];
429 case MAPSCR_TEMP6:
430 return origin_scr->layermap[5];
431 case MAPSCR_SCROLL0:
432 return scrolling_map+1;
433 case MAPSCR_SCROLL1:
434 return special_warp_return_scr->layermap[0];
435 case MAPSCR_SCROLL2:
436 return special_warp_return_scr->layermap[1];
437 case MAPSCR_SCROLL3:
438 return special_warp_return_scr->layermap[2];
439 case MAPSCR_SCROLL4:
440 return special_warp_return_scr->layermap[3];
441 case MAPSCR_SCROLL5:
442 return special_warp_return_scr->layermap[4];
443 case MAPSCR_SCROLL6:
444 return special_warp_return_scr->layermap[5];
445 default:
446 9 return (ref / MAPSCRS + 1);
447 }
448 9 }
449 21 int32_t getScreen(int32_t ref)
450 {
451
1/15
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
21 switch(ref)
452 {
453 case MAPSCR_TEMP0:
454 return cur_screen;
455 case MAPSCR_TEMP1:
456 return origin_scr->layerscreen[0];
457 case MAPSCR_TEMP2:
458 return origin_scr->layerscreen[1];
459 case MAPSCR_TEMP3:
460 return origin_scr->layerscreen[2];
461 case MAPSCR_TEMP4:
462 return origin_scr->layerscreen[3];
463 case MAPSCR_TEMP5:
464 return origin_scr->layerscreen[4];
465 case MAPSCR_TEMP6:
466 return origin_scr->layerscreen[5];
467 case MAPSCR_SCROLL0:
468 return scrolling_hero_screen;
469 case MAPSCR_SCROLL1:
470 return special_warp_return_scr->layerscreen[0];
471 case MAPSCR_SCROLL2:
472 return special_warp_return_scr->layerscreen[1];
473 case MAPSCR_SCROLL3:
474 return special_warp_return_scr->layerscreen[2];
475 case MAPSCR_SCROLL4:
476 return special_warp_return_scr->layerscreen[3];
477 case MAPSCR_SCROLL5:
478 return special_warp_return_scr->layerscreen[4];
479 case MAPSCR_SCROLL6:
480 return special_warp_return_scr->layerscreen[5];
481 default:
482 21 return (ref % MAPSCRS);
483 }
484 21 }
485
486 654489967 static ffcdata* get_ffc(ffc_id_t ffc_id)
487 {
488 654489967 return &get_scr_for_region_index_offset(ffc_id / MAXFFCS)->getFFC(ffc_id % MAXFFCS);
489 }
490
491 94642 dword get_subref(int sub, byte ty, byte pg, word ind)
492 {
493 byte s;
494
2/2
✓ Branch 0 taken 79480 times.
✓ Branch 1 taken 15162 times.
94642 if(sub == -1) //special; load current
495 {
496
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15162 times.
15162 if (new_sub_indexes[ty] < 0) return 0;
497 15162 s = new_sub_indexes[ty];
498 15162 }
499
1/2
✓ Branch 0 taken 79480 times.
✗ Branch 1 not taken.
79480 else if(unsigned(sub) < 256)
500 79480 s = sub;
501 else return 0;
502 94642 ++ty; //type is offset by 1
503 94642 return (s<<24)|(pg<<16)|((ty&0x7)<<13)|(ind&0x1FFF);
504 94642 }
505 414110 std::tuple<byte,int8_t,byte,word> from_subref(dword ref)
506 {
507 414110 byte type = (ref>>13)&0x07;
508
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 414110 times.
414110 if(!type)
509 return { 0, -1, 0, 0 };
510
511 414110 byte sub = (ref>>24)&0xFF;
512 414110 byte pg = (ref>>16)&0xFF;
513 414110 word ind = (ref)&0x1FFF;
514 414110 return { sub, type-1, pg, ind };
515 414110 }
516
517 334633 std::tuple<ZCSubscreen*,SubscrPage*,SubscrWidget*,byte> load_subscreen_ref(dword ref)
518 {
519 1673165 auto [sub,ty,pg,ind] = from_subref(ref);
520 334633 ZCSubscreen* sbscr = nullptr;
521 334633 SubscrPage* sbpg = nullptr;
522 334633 SubscrWidget* sbwidg = nullptr;
523
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 334633 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
334633 switch(ty)
524 {
525 case sstACTIVE:
526
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 334633 times.
334633 if(sub < subscreens_active.size())
527 334633 sbscr = &subscreens_active[sub];
528 334633 break;
529 case sstPASSIVE:
530 if(sub < subscreens_passive.size())
531 sbscr = &subscreens_passive[sub];
532 break;
533 case sstOVERLAY:
534 if(sub < subscreens_overlay.size())
535 sbscr = &subscreens_overlay[sub];
536 break;
537 }
538
1/2
✓ Branch 0 taken 334633 times.
✗ Branch 1 not taken.
334633 if(sbscr)
539 {
540
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 334633 times.
334633 if(pg < sbscr->pages.size())
541 669266 sbpg = &sbscr->pages[pg];
542 334633 }
543 else return { nullptr, nullptr, nullptr, -1 }; //no subscreen
544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 334633 times.
334633 if(sbpg)
545 {
546
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 334633 times.
334633 if(ind < sbpg->size())
547 669266 sbwidg = sbpg->at(ind);
548 334633 }
549 334633 return { sbscr, sbpg, sbwidg, ty };
550 334633 }
551 174863 std::pair<ZCSubscreen*,byte> load_subdata(dword ref)
552 {
553 174863 auto [sub,_pg,_widg,ty] = load_subscreen_ref(ref);
554 174863 return { sub, ty };
555 }
556 56028 std::pair<SubscrPage*,byte> load_subpage(dword ref)
557 {
558 56028 auto [_sub,pg,_widg,ty] = load_subscreen_ref(ref);
559 56028 return { pg, ty };
560 }
561 103742 std::pair<SubscrWidget*,byte> load_subwidg(dword ref)
562 {
563 103742 auto [_sub,_pg,widg,ty] = load_subscreen_ref(ref);
564 103742 return { widg, ty };
565 }
566
567 #include "zconsole/ConsoleLogger.h"
568
569 //no ifdef here
570 extern CConsoleLoggerEx zscript_coloured_console;
571
572 bool FFScript::isNumber(char chr)
573 {
574 if ( chr >= '0' )
575 {
576 if ( chr <= '9' ) return true;
577 }
578 return false;
579 }
580
581 int32_t FFScript::ilen(char *p)
582 {
583 int32_t ret = 0; int32_t pos = 0;
584 if(p[pos] == '-')
585 ret++;
586 for(; FFCore.isNumber(p[pos + ret]); ++ret);
587 return ret;
588 }
589
590 int32_t FFScript::atox(char *ip_str)
591 {
592 char tmp[2]={'2','\0'};
593 int32_t op_val=0, i=0, ip_len = strlen(ip_str);
594
595 if(strncmp(ip_str, "0x", 2) == 0)
596 {
597 ip_str +=2;
598 ip_len -=2;
599 }
600
601 for(i=0;i<ip_len;i++)
602 {
603 op_val *= 0x10;
604 switch(ip_str[i])
605 {
606 case 'a':
607 op_val += 0xa;
608 break;
609 case 'b':
610 op_val += 0xb;
611 break;
612 case 'c':
613 op_val += 0xc;
614 break;
615 case 'd':
616 op_val += 0xd;
617 break;
618 case 'e':
619 op_val += 0xe;
620 break;
621 case 'f':
622 op_val += 0xf;
623 break;
624 case '0':
625 case '1':
626 case '2':
627 case '3':
628 case '4':
629 case '5':
630 case '6':
631 case '7':
632 case '8':
633 case '9':
634 tmp[0] = ip_str[i];
635 op_val += atoi(tmp);
636 break;
637 default :
638 op_val += 0x0;
639 break;
640 }
641 }
642 return op_val;
643 }
644
645 char runningItemScripts[256] = {0};
646
647 //item *FFCore.temp_ff_item = NULL;
648 //enemy *FFCore.temp_ff_enemy = NULL;
649 //weapon *FFCore.temp_ff_lweapon = NULL;
650 //weapon *FFCore.temp_ff_eweapon = NULL;
651
652 extern int32_t directItemA;
653 extern int32_t directItemB;
654 extern int32_t directItemX;
655 extern int32_t directItemY;
656
657
658 #ifdef _MSC_VER
659 #pragma warning ( disable : 4800 ) //int32_t to bool town. population: lots.
660 #endif
661
662 //! New datatype vars for 2.54:
663
664 //spritedata sp->member
665
666
667 using std::string;
668
669 extern char *guy_string[];
670 extern int32_t skipcont;
671
672 PALETTE tempgreypal; //Palettes go here. This is used for Greyscale() / Monochrome()
673 PALETTE userPALETTE[256]; //Palettes go here. This is used for Greyscale() / Monochrome()
674 PALETTE tempblackpal; //Used for storing the palette while fading to black
675
676 byte FF_hero_action; //This way, we can make safe replicas of internal Hero actions to be set by script.
677
678 int32_t FF_screenbounds[4]; //edges of the screen, left, right, top, bottom used for where to scroll.
679 int32_t FF_screen_dimensions[4]; //height, width, displaywidth, displayheight
680 int32_t FF_subscreen_dimensions[4];
681 int32_t FF_eweapon_removal_bounds[4]; //left, right, top, bottom coordinates for automatic eweapon removal.
682 int32_t FF_lweapon_removal_bounds[4]; //left, right, top, bottom coordinates for automatic lweapon removal.
683 int32_t FF_clocks[FFSCRIPTCLASS_CLOCKS]; //Will be used for Heroaction, anims, and so forth
684 byte ScriptDrawingRules[SCRIPT_DRAWING_RULES];
685 int32_t FF_UserMidis[NUM_USER_MIDI_OVERRIDES]; //MIDIs to use for Game Over, and similar to override system defaults.
686
687 int32_t legacy_get_int_arr(const int32_t ptr, int32_t indx);
688 void legacy_set_int_arr(const int32_t ptr, int32_t indx, int32_t val);
689 int32_t legacy_sz_int_arr(const int32_t ptr);
690
691 //We gain some speed by not passing as arguments
692 int32_t sarg1 = 0;
693 int32_t sarg2 = 0;
694 int32_t sarg3 = 0;
695 vector<int32_t> *sargvec;
696 string *sargstr;
697 refInfo *ri = NULL;
698 script_data *curscript = NULL;
699 int32_t(*stack)[MAX_SCRIPT_REGISTERS] = NULL;
700 bounded_vec<word, int32_t>* ret_stack;
701 vector<int32_t> zs_vargs;
702 ScriptType curScriptType;
703 word curScriptNum;
704 int32_t curScriptIndex;
705 bool script_funcrun = false;
706 string* destructstr = nullptr;
707 size_t gen_frozen_index = 0;
708
709 static vector<ScriptType> curScriptType_cache;
710 static vector<int32_t> curScriptNum_cache;
711 static vector<int32_t> curScriptIndex_cache;
712 static vector<int32_t> sarg1cache;
713 static vector<int32_t> sarg2cache;
714 static vector<int32_t> sarg3cache;
715 static vector<vector<int32_t>*> sargvec_cache;
716 static vector<string*> sargstr_cache;
717 static vector<refInfo*> ricache;
718 static vector<script_data*> sdcache;
719 static vector<int32_t(*)[MAX_SCRIPT_REGISTERS]> stackcache;
720 static vector<bounded_vec<word, int32_t>*> ret_stack_cache;
721 820 void push_ri()
722 {
723 820 sarg1cache.push_back(sarg1);
724 820 sarg2cache.push_back(sarg2);
725 820 sarg3cache.push_back(sarg3);
726 820 curScriptType_cache.push_back(curScriptType);
727 820 curScriptNum_cache.push_back(curScriptNum);
728 820 curScriptIndex_cache.push_back(curScriptIndex);
729 820 sargvec_cache.push_back(sargvec);
730 820 sargstr_cache.push_back(sargstr);
731 820 ricache.push_back(ri);
732 820 sdcache.push_back(curscript);
733 820 stackcache.push_back(stack);
734 820 ret_stack_cache.push_back(ret_stack);
735 820 }
736 820 void pop_ri()
737 {
738 820 sarg1 = sarg1cache.back(); sarg1cache.pop_back();
739 820 sarg2 = sarg2cache.back(); sarg2cache.pop_back();
740 820 sarg3 = sarg3cache.back(); sarg3cache.pop_back();
741 820 curScriptType = curScriptType_cache.back(); curScriptType_cache.pop_back();
742 820 curScriptNum = curScriptNum_cache.back(); curScriptNum_cache.pop_back();
743 820 curScriptIndex = curScriptIndex_cache.back(); curScriptIndex_cache.pop_back();
744 820 sargvec = sargvec_cache.back(); sargvec_cache.pop_back();
745 820 sargstr = sargstr_cache.back(); sargstr_cache.pop_back();
746 820 ri = ricache.back(); ricache.pop_back();
747 820 curscript = sdcache.back(); sdcache.pop_back();
748 820 stack = stackcache.back(); stackcache.pop_back();
749 820 ret_stack = ret_stack_cache.back(); ret_stack_cache.pop_back();
750 820 }
751
752 //START HELPER FUNCTIONS
753 ///-------------------------------------//
754 // Helper Functions //
755 ///-------------------------------------//
756
757 104566 void SH::write_stack(const uint32_t stackoffset, const int32_t value)
758 {
759
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 104566 times.
104566 if(stackoffset >= MAX_SCRIPT_REGISTERS)
760 {
761 Z_scripterrlog("Stack over or underflow, stack pointer = %ld\n", stackoffset);
762 return;
763 }
764
765 104566 (*stack)[stackoffset] = value;
766 104566 }
767
768 758420898 int32_t SH::read_stack(const uint32_t stackoffset)
769 {
770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 758420898 times.
758420898 if(stackoffset >= MAX_SCRIPT_REGISTERS)
771 {
772 Z_scripterrlog("Stack over or underflow, stack pointer = %ld\n", stackoffset);
773 return -10000;
774 }
775
776 758420898 return (*stack)[stackoffset];
777 758420898 }
778
779 ///----------------------------//
780 // Misc. //
781 ///----------------------------//
782
783 byte flagpos;
784 int32_t flagval;
785 21469831 void clear_ornextflag()
786 {
787 21469831 flagpos = 0;
788 21469831 flagval = 0;
789 21469831 }
790 145861533 void ornextflag(bool flag)
791 {
792
2/2
✓ Branch 0 taken 143700973 times.
✓ Branch 1 taken 2160560 times.
145861533 if(flag) flagval |= 1<<flagpos;
793 145861533 ++flagpos;
794 145861533 }
795
796 11161012 int32_t get_screenflags(mapscr *m, int32_t flagset)
797 {
798 11161012 clear_ornextflag();
799
800
5/11
✓ Branch 0 taken 4807572 times.
✓ Branch 1 taken 6263768 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 52 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 89609 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
11161012 switch(flagset)
801 {
802 case 0: // Room Type
803 4807572 ornextflag(m->flags6&1);
804 4807572 ornextflag(m->flags6&2);
805 4807572 ornextflag(m->flags7&8);
806 4807572 break;
807
808 case 1: // View
809 6263768 ornextflag(m->flags3&8);
810 6263768 ornextflag(m->flags7&16);
811 6263768 ornextflag(m->flags3&16);
812 6263768 ornextflag(m->flags3&64);
813 6263768 ornextflag(m->flags7&2);
814 6263768 ornextflag(m->flags7&1);
815 6263768 ornextflag(m->flags&fDARK);
816 6263768 ornextflag(m->flags9&fDARK_DITHER);
817 6263768 ornextflag(m->flags9&fDARK_TRANS);
818 6263768 break;
819
820 case 2: // Secrets
821 11 ornextflag(m->flags&1);
822 11 ornextflag(m->flags5&16);
823 11 ornextflag(m->flags6&4);
824 11 ornextflag(m->flags6&32);
825 11 break;
826
827 case 3: // Warp
828 ornextflag(m->flags5&4);
829 ornextflag(m->flags5&8);
830 ornextflag(m->flags&64);
831 ornextflag(m->flags8&64);
832 ornextflag(m->flags3&32);
833 ornextflag(m->flags9&fDISABLE_MIRROR);
834 ornextflag(m->flags10&fMAZE_CAN_GET_LOST);
835 ornextflag(m->flags10&fMAZE_LOOPY);
836 break;
837
838 case 4: // Item
839 52 ornextflag(m->flags3&1);
840 52 ornextflag(m->flags7&4);
841 52 ornextflag(m->flags8&0x40);
842 52 ornextflag(m->flags8&0x80);
843 52 ornextflag(m->flags9&0x01);
844 52 ornextflag(m->flags9&0x02);
845 52 ornextflag(m->flags9&fBELOWRETURN);
846 52 break;
847
848 case 5: // Combo
849 ornextflag((m->flags2>>4)&2);
850 ornextflag(m->flags3&2);
851 ornextflag(m->flags5&2);
852 ornextflag(m->flags6&64);
853 break;
854
855 case 6: // Save
856 ornextflag(m->flags4&64);
857 ornextflag(m->flags4&128);
858 ornextflag(m->flags6&8);
859 ornextflag(m->flags6&16);
860 break;
861
862 case 7: // FFC
863 ornextflag(m->flags6&128);
864 ornextflag(m->flags5&128);
865 break;
866
867 case 8: // Whistle
868 ornextflag(m->flags&16);
869 ornextflag(m->flags7&64);
870 ornextflag(m->flags7&128);
871 break;
872
873 case 9: // Misc
874 89609 ornextflag(m->flags&32);
875 89609 ornextflag(m->flags5&64);
876 89609 flagval |= m->flags8<<2;
877 89609 break;
878 }
879
880 11161012 return flagval;
881 }
882
883 4473523 int32_t get_screeneflags(mapscr *m, int32_t flagset)
884 {
885 4473523 clear_ornextflag();
886
887
2/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4473221 times.
✓ Branch 3 taken 302 times.
4473523 switch(flagset)
888 {
889 case 0:
890 flagval |= m->flags11&0x1F;
891 break;
892
893 case 1:
894 4473221 ornextflag(m->flags11&32);
895 4473221 ornextflag(m->flags11&64);
896 4473221 ornextflag(m->flags3&4);
897 4473221 ornextflag(m->flags11&128);
898 4473221 ornextflag((m->flags2>>4)&4);
899 4473221 break;
900
901 case 2:
902 302 ornextflag(m->flags3&128);
903 302 ornextflag(m->flags&2);
904 302 ornextflag((m->flags2>>4)&8);
905 302 ornextflag(m->flags4&16);
906 302 ornextflag(m->flags9&fENEMY_WAVES);
907 302 break;
908 }
909
910 4473523 return flagval;
911 }
912
913 int32_t get_mi(int32_t ref)
914 {
915 auto result = decode_mapdata_ref(ref);
916 if (result.canonical())
917 {
918 if (result.screen >= MAPSCRSNORMAL) return -1;
919 return mapind(result.scr->map, result.screen);
920 }
921 else if (result.current())
922 {
923 if (result.screen >= MAPSCRSNORMAL) return -1;
924 return mapind(cur_map, result.screen);
925 }
926 else if (result.scrolling())
927 {
928 if (result.screen >= MAPSCRSNORMAL) return -1;
929 return mapind(scrolling_map, result.screen);
930 }
931
932 return -1;
933 }
934
935 int32_t get_ref_map_index(int32_t ref)
936 {
937 if (ref >= 0)
938 return ref;
939
940 auto result = decode_mapdata_ref(ref);
941 if (result.current())
942 {
943 return map_screen_index(cur_map, result.screen);
944 }
945 else if (result.scrolling())
946 {
947 return map_screen_index(scrolling_map, result.screen);
948 }
949
950 return -1;
951 }
952
953 template <typename T>
954 273448983 static T* ResolveSprite(int32_t uid, const char* name)
955 {
956
10/10
✓ Branch 0 taken 43218384 times.
✓ Branch 1 taken 966 times.
✓ Branch 2 taken 1641473 times.
✓ Branch 3 taken 597888 times.
✓ Branch 4 taken 162664717 times.
✓ Branch 5 taken 2612 times.
✓ Branch 6 taken 58765181 times.
✓ Branch 7 taken 183114 times.
✓ Branch 8 taken 6373774 times.
✓ Branch 9 taken 874 times.
273448983 if (!uid)
957 {
958
10/20
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 966 times.
✓ Branch 4 taken 597888 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 597888 times.
✓ Branch 8 taken 2612 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 2612 times.
✓ Branch 12 taken 183114 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 183114 times.
✓ Branch 16 taken 874 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 874 times.
785454 scripting_log_error_with_context("Invalid sprite: null pointer");
959 785454 return nullptr;
960 }
961
962
8/10
✗ Branch 0 not taken.
✓ Branch 1 taken 43218384 times.
✓ Branch 2 taken 180 times.
✓ Branch 3 taken 1641293 times.
✓ Branch 4 taken 7107 times.
✓ Branch 5 taken 162657610 times.
✓ Branch 6 taken 20166 times.
✓ Branch 7 taken 58745015 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6373774 times.
272663529 if (auto s = sprite::getByUID(uid))
963 {
964
9/18
✗ Branch 0 not taken.
✓ Branch 1 taken 43218384 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1641293 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1641293 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 162657610 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 162657610 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 58745015 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 58745015 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 6373774 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 6373774 times.
272636076 if (auto s2 = dynamic_cast<T*>(s))
965 272636076 return s2;
966
967 scripting_log_error_with_context("Invalid sprite using UID = {} - but that sprite is not a {}", uid, name);
968 return nullptr;
969 }
970
971 27453 scripting_log_error_with_context("Invalid sprite using UID = {} - but that sprite does not exist", uid);
972 27453 return nullptr;
973 273448983 }
974
975 43219350 sprite* ResolveBaseSprite(int32_t uid)
976 {
977 43219350 return ResolveSprite<sprite>(uid, "sprite");
978 }
979
980 2239361 item* ResolveItemSprite(int32_t uid)
981 {
982 2239361 return ResolveSprite<item>(uid, "item");
983 }
984
985 162667317 enemy* ResolveNpc(int32_t uid)
986 {
987 162667317 return ResolveSprite<enemy>(uid, "npc");
988 }
989
990 static weapon* ResolveEWeapon_checkSpriteList(int32_t uid)
991 {
992 // Check here first (for the error logging.)
993 const char* name = "eweapon";
994 auto spr = ResolveSprite<weapon>(uid, name);
995
996 // Double check this is from the right sprite list.
997 if (spr && !Ewpns.getByUID(uid))
998 {
999 scripting_log_error_with_context("Invalid sprite using UID = {} - but that sprite is not a {}", uid, name);
1000 return nullptr;
1001 }
1002
1003 return spr;
1004 }
1005
1006 598 static weapon* ResolveLWeapon_checkSpriteList(int32_t uid)
1007 {
1008 // Check here first (for the error logging.)
1009 598 const char* name = "lweapon";
1010 598 auto spr = ResolveSprite<weapon>(uid, name);
1011
1012 // Double check this is from the right sprite list.
1013
2/4
✓ Branch 0 taken 598 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 598 times.
598 if (spr && !Lwpns.getByUID(uid))
1014 {
1015 scripting_log_error_with_context("Invalid sprite using UID = {} - but that sprite is not a {}", uid, name);
1016 return nullptr;
1017 }
1018
1019 598 return spr;
1020 598 }
1021
1022 // For compat, get the first `combo_trigger` of the current `ri->combosref`
1023 3224 combo_trigger* get_first_combo_trigger()
1024 {
1025
2/4
✓ Branch 0 taken 3224 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3224 times.
3224 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
1026 return nullptr;
1027
2/2
✓ Branch 0 taken 139 times.
✓ Branch 1 taken 3085 times.
3224 if(combobuf[ri->combosref].triggers.empty())
1028 139 return &(combobuf[ri->combosref].triggers.emplace_back());
1029 3085 return &(combobuf[ri->combosref].triggers[0]);
1030 3224 }
1031 // Get the combo trigger pointed to by `ref` (usually ri->combotrigref)
1032 combo_trigger* get_combo_trigger(dword ref)
1033 {
1034 byte idx = (ref >> 24) & 0xFF;
1035 dword cid = ref & 0x00FFFFFF;
1036 if(cid >= MAXCOMBOS)
1037 {
1038 scripting_log_error_with_context("Invalid combotrigger ID: {}-{}", idx, cid);
1039 return nullptr;
1040 }
1041 newcombo& cmb = combobuf[cid];
1042 if(idx >= cmb.triggers.size())
1043 {
1044 scripting_log_error_with_context("Invalid combotrigger ID: {}-{}", idx, cid);
1045 return nullptr;
1046 }
1047 return &(cmb.triggers[idx]);
1048 }
1049 // Get the combo ID of the trigger pointed to by `ref` (usually ri->combotrigref)
1050 dword get_combo_from_trigger_ref(dword ref)
1051 {
1052 dword cid = ref & 0x00FFFFFF;
1053 DCHECK(cid < MAXCOMBOS);
1054 return cid;
1055 }
1056
1057 ///------------------------------------------------//
1058 // Pointer Handling Functions //
1059 ///------------------------------------------------//
1060
1061 //LWeapon Helper
1062 class LwpnH : public SH
1063 {
1064
1065 public:
1066
1067
1068 static defWpnSprite getDefWeaponSprite(weapon *wp)
1069 {
1070 switch(wp->id)
1071 {
1072 case wNone: return ws_0;
1073 case wSword: return ws_0;
1074 case wBeam: return wsBeam;
1075 case wBrang : return wsBrang;
1076 case wBomb: return wsBomb;
1077 case wSBomb: return wsSBomb;
1078 case wLitBomb: return wsBombblast;
1079 case wLitSBomb: return wsBombblast;
1080 case wArrow: return wsArrow;
1081 case wRefArrow: return wsArrow;
1082 case wFire: return wsFire;
1083 case wRefFire: return wsFire;
1084 case wRefFire2: return wsFire;
1085 case wWhistle: return wsUnused45;
1086 case wBait: return wsBait;
1087 case wWand: return wsWandHandle;
1088 case wMagic: return wsMagic;
1089 case wCatching: return wsUnused45;
1090 case wWind: return wsWind;
1091 case wRefMagic: return wsRefMagic;
1092 case wRefFireball: return wsRefFireball;
1093 case wRefRock: return wsRock;
1094 case wHammer: return wsHammer;
1095 case wHookshot: return wsHookshotHead;
1096 case wHSHandle: return wsHookshotHandle;
1097 case wHSChain: return wsHookshotChainH;
1098 case wSSparkle: return wsSilverSparkle;
1099 case wFSparkle: return wsGoldSparkle;
1100 case wSmack: return wsHammerSmack;
1101 case wPhantom: return wsUnused45;
1102 case wCByrna: return wsByrnaCane;
1103 case wRefBeam: return wsRefBeam;
1104 case wStomp: return wsUnused45;
1105 case lwMax: return wsUnused45;
1106 case wScript1:
1107 case wScript2:
1108 case wScript3:
1109 case wScript4:
1110 case wScript5:
1111 case wScript6:
1112 case wScript7:
1113 case wScript8:
1114 case wScript9:
1115 case wScript10: return ws_0;
1116 case wIce: return wsIce; //new
1117 case wFlame: return wsEFire2; //new
1118 //not implemented; t/b/a
1119 case wSound:
1120 case wThrown:
1121 case wPot:
1122 case wLit:
1123 case wBombos:
1124 case wEther:
1125 case wQuake:
1126 case wSword180:
1127 case wSwordLA: return wsUnused45;
1128
1129 case ewFireball: return wsFireball2;
1130 case ewArrow: return wsEArrow;
1131 case ewBrang: return wsBrang;
1132 case ewSword: return wsEBeam;
1133 case ewRock: return wsRock;
1134 case ewMagic: return wsEMagic;
1135 case ewBomb: return wsEBomb;
1136 case ewSBomb: return wsESbomb;
1137 case ewLitBomb: return wsEBombblast;
1138 case ewLitSBomb: return wsESbombblast;
1139 case ewFireTrail: return wsEFiretrail;
1140 case ewFlame: return wsEFire;
1141 case ewWind: return wsEWind;
1142 case ewFlame2: return wsEFire2;
1143 case ewFlame2Trail: return wsEFiretrail2;
1144 case ewIce: return wsIce;
1145 case ewFireball2: return wsFireball2;
1146 default: return wsUnused45;
1147 }
1148 };
1149
1150 19653 static int32_t loadWeapon(const int32_t uid)
1151 {
1152 19653 tempweapon = ResolveSprite<weapon>(uid, "lweapon");
1153
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19653 times.
19653 if (!tempweapon)
1154 return _InvalidSpriteUID;
1155
1156 19653 return _NoError;
1157 19653 }
1158
1159 19653 static INLINE weapon *getWeapon()
1160 {
1161 19653 return tempweapon;
1162 }
1163
1164 35353 static INLINE void clearTemp()
1165 {
1166 35353 tempweapon = NULL;
1167 35353 }
1168
1169 private:
1170
1171 static weapon *tempweapon;
1172 };
1173
1174 weapon *LwpnH::tempweapon = NULL;
1175
1176 //EWeapon Helper
1177 class EwpnH : public SH
1178 {
1179
1180 public:
1181
1182 defWpnSprite getDefWeaponSprite(weapon *wp)
1183 {
1184 switch(wp->id)
1185 {
1186 case wNone: return ws_0;
1187 case wSword: return ws_0;
1188 case wBeam: return wsBeam;
1189 case wBrang : return wsBrang;
1190 case wBomb: return wsBomb;
1191 case wSBomb: return wsSBomb;
1192 case wLitBomb: return wsBombblast;
1193 case wLitSBomb: return wsBombblast;
1194 case wArrow: return wsArrow;
1195 case wRefArrow: return wsArrow;
1196 case wFire: return wsFire;
1197 case wRefFire: return wsFire;
1198 case wRefFire2: return wsFire;
1199 case wWhistle: return wsUnused45;
1200 case wBait: return wsBait;
1201 case wWand: return wsWandHandle;
1202 case wMagic: return wsMagic;
1203 case wCatching: return wsUnused45;
1204 case wWind: return wsWind;
1205 case wRefMagic: return wsRefMagic;
1206 case wRefFireball: return wsRefFireball;
1207 case wRefRock: return wsRock;
1208 case wHammer: return wsHammer;
1209 case wHookshot: return wsHookshotHead;
1210 case wHSHandle: return wsHookshotHandle;
1211 case wHSChain: return wsHookshotChainH;
1212 case wSSparkle: return wsSilverSparkle;
1213 case wFSparkle: return wsGoldSparkle;
1214 case wSmack: return wsHammerSmack;
1215 case wPhantom: return wsUnused45;
1216 case wCByrna: return wsByrnaCane;
1217 case wRefBeam: return wsRefBeam;
1218 case wStomp: return wsUnused45;
1219 case lwMax: return wsUnused45;
1220 case wScript1:
1221 case wScript2:
1222 case wScript3:
1223 case wScript4:
1224 case wScript5:
1225 case wScript6:
1226 case wScript7:
1227 case wScript8:
1228 case wScript9:
1229 case wScript10: return ws_0;
1230 case wIce: return wsIce; //new
1231 case wFlame: return wsEFire2; //new
1232 //not implemented; t/b/a
1233 case wSound:
1234 case wThrown:
1235 case wPot:
1236 case wLit:
1237 case wBombos:
1238 case wEther:
1239 case wQuake:
1240 case wSword180:
1241 case wSwordLA: return wsUnused45;
1242
1243 case ewFireball: return wsFireball2;
1244 case ewArrow: return wsEArrow;
1245 case ewBrang: return wsBrang;
1246 case ewSword: return wsEBeam;
1247 case ewRock: return wsRock;
1248 case ewMagic: return wsEMagic;
1249 case ewBomb: return wsEBomb;
1250 case ewSBomb: return wsESbomb;
1251 case ewLitBomb: return wsEBombblast;
1252 case ewLitSBomb: return wsESbombblast;
1253 case ewFireTrail: return wsEFiretrail;
1254 case ewFlame: return wsEFire;
1255 case ewWind: return wsEWind;
1256 case ewFlame2: return wsEFire2;
1257 case ewFlame2Trail: return wsEFiretrail2;
1258 case ewIce: return wsIce;
1259 case ewFireball2: return wsFireball2;
1260 default: return wsUnused45;
1261 }
1262 };
1263
1264 208946 static int32_t loadWeapon(const int32_t uid)
1265 {
1266 208946 tempweapon = ResolveSprite<weapon>(uid, "eweapon");
1267
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 208946 times.
208946 if (!tempweapon)
1268 return _InvalidSpriteUID;
1269
1270 208946 return _NoError;
1271 208946 }
1272
1273 208946 static INLINE weapon *getWeapon()
1274 {
1275 208946 return tempweapon;
1276 }
1277
1278 35353 static INLINE void clearTemp()
1279 {
1280 35353 tempweapon = NULL;
1281 35353 }
1282
1283 private:
1284
1285 static weapon *tempweapon;
1286 };
1287
1288 weapon *EwpnH::tempweapon = NULL;
1289
1290 35353 void clearScriptHelperData()
1291 {
1292 35353 GuyH::clearTemp();
1293 35353 LwpnH::clearTemp();
1294 35353 EwpnH::clearTemp();
1295 35353 ItemH::clearTemp();
1296 35353 }
1297 ////END HELPER FUNCTIONS
1298
1299 static int32_t numInstructions = 0; // Used to detect hangs
1300 static bool scriptCanSave = true;
1301
1302 687929326 static ScriptEngineData& get_script_engine_data(ScriptType type, int index)
1303 {
1304
8/8
✓ Branch 0 taken 655880991 times.
✓ Branch 1 taken 32048335 times.
✓ Branch 2 taken 655877646 times.
✓ Branch 3 taken 3345 times.
✓ Branch 4 taken 623962371 times.
✓ Branch 5 taken 31915275 times.
✓ Branch 6 taken 17798 times.
✓ Branch 7 taken 623944573 times.
687929326 if (type == ScriptType::DMap || type == ScriptType::OnMap || type == ScriptType::ScriptedPassiveSubscreen || type == ScriptType::ScriptedActiveSubscreen)
1305 {
1306 // `index` is used for dmapref, not for different script engine data.
1307 63984753 index = 0;
1308 63984753 }
1309
2/2
✓ Branch 0 taken 687868470 times.
✓ Branch 1 taken 60856 times.
687929326 if (type == ScriptType::EngineSubscreen)
1310 {
1311 // `index` is used for subdataref, not for different script engine data.
1312 60856 index = 0;
1313 60856 }
1314
1315 687929326 return scriptEngineDatas[{type, index}];
1316 }
1317
1318 965873 static bool script_engine_data_exists(ScriptType type, int index)
1319 {
1320
5/8
✓ Branch 0 taken 962712 times.
✓ Branch 1 taken 3161 times.
✓ Branch 2 taken 962712 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 962712 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 962712 times.
965873 if (type == ScriptType::DMap || type == ScriptType::OnMap || type == ScriptType::ScriptedPassiveSubscreen || type == ScriptType::ScriptedActiveSubscreen)
1321 {
1322 // `index` is used for dmapref, not for different script engine data.
1323 3161 index = 0;
1324 3161 }
1325
1/2
✓ Branch 0 taken 965873 times.
✗ Branch 1 not taken.
965873 if (type == ScriptType::EngineSubscreen)
1326 {
1327 // `index` is used for subdataref, not for different script engine data.
1328 index = 0;
1329 }
1330
1331 965873 return scriptEngineDatas.contains({type, index});
1332 }
1333
1334 46 static ScriptEngineData& get_script_engine_data(ScriptType type)
1335 {
1336 46 return get_script_engine_data(type, 0);
1337 }
1338
1339 1077 void FFScript::clear_script_engine_data()
1340 {
1341 1077 scriptEngineDatas.clear();
1342 1077 }
1343
1344 2300921 void FFScript::reset_script_engine_data(ScriptType type, int index)
1345 {
1346 2300921 get_script_engine_data(type, index).reset();
1347 2300921 }
1348
1349 80964 void on_reassign_script_engine_data(ScriptType type, int index)
1350 {
1351 80964 auto& data = get_script_engine_data(type, index);
1352 80964 data.ref.Clear();
1353 80964 data.initialized = false;
1354 80964 FFScript::deallocateAllScriptOwned(type, index);
1355 80964 }
1356
1357 1124576 void FFScript::clear_script_engine_data(ScriptType type, int index)
1358 {
1359
4/8
✓ Branch 0 taken 1124576 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1124576 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1124576 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1124576 times.
1124576 if (type == ScriptType::DMap || type == ScriptType::OnMap || type == ScriptType::ScriptedPassiveSubscreen || type == ScriptType::ScriptedActiveSubscreen)
1360 {
1361 // `index` is used for dmapref, not for different script engine data.
1362 index = 0;
1363 }
1364
1/2
✓ Branch 0 taken 1124576 times.
✗ Branch 1 not taken.
1124576 if (type == ScriptType::EngineSubscreen)
1365 {
1366 // `index` is used for subdataref, not for different script engine data.
1367 index = 0;
1368 }
1369
1370 1124576 auto it = scriptEngineDatas.find({type, index});
1371
2/2
✓ Branch 0 taken 1124420 times.
✓ Branch 1 taken 156 times.
1124576 if (it != scriptEngineDatas.end())
1372 {
1373 156 scriptEngineDatas.erase(it);
1374 156 }
1375 1124576 }
1376
1377 133254 void FFScript::clear_script_engine_data_of_type(ScriptType type)
1378 {
1379 280078139 std::erase_if(scriptEngineDatas, [&](auto& kv) { return kv.first.first == type; });
1380 133254 }
1381
1382 307 refInfo& FFScript::ref(ScriptType type, int index)
1383 {
1384 307 return get_script_engine_data(type, index).ref;
1385 }
1386
1387 63823616 byte& FFScript::doscript(ScriptType type, int index)
1388 {
1389
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 63823616 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
63823616 if (type == ScriptType::Generic && unsigned(index) < NUMSCRIPTSGENERIC)
1390 return user_genscript::get(index).doscript();
1391 63823616 return get_script_engine_data(type, index).doscript;
1392 63823616 }
1393
1394 521992228 bool& FFScript::waitdraw(ScriptType type, int index)
1395 {
1396 521992228 return get_script_engine_data(type, index).waitdraw;
1397 }
1398
1399 // Returns true if registers had to be initialized.
1400 26669885 static bool set_current_script_engine_data(ScriptType type, int script, int index)
1401 {
1402 26669885 bool got_initialized = false;
1403
1404 26669885 auto& data = get_script_engine_data(type, index);
1405 26669885 ri = &data.ref;
1406 26669885 stack = &data.stack;
1407 26669885 ret_stack = &data.ret_stack;
1408
1409 // By default, make `Screen->` refer to the top-left screen.
1410 // Will be set to something more specific for relevant script types.
1411 26669885 ri->screenref = cur_screen;
1412
1413
16/18
✗ Branch 0 not taken.
✓ Branch 1 taken 11172226 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 212924 times.
✓ Branch 4 taken 147334 times.
✓ Branch 5 taken 7460 times.
✓ Branch 6 taken 15539 times.
✓ Branch 7 taken 11113138 times.
✓ Branch 8 taken 2141119 times.
✓ Branch 9 taken 1542 times.
✓ Branch 10 taken 1330339 times.
✓ Branch 11 taken 74519 times.
✓ Branch 12 taken 114 times.
✓ Branch 13 taken 12244 times.
✓ Branch 14 taken 1402 times.
✓ Branch 15 taken 15162 times.
✓ Branch 16 taken 56311 times.
✓ Branch 17 taken 368512 times.
26669885 switch (type)
1414 {
1415 case ScriptType::FFC:
1416 {
1417 11172226 curscript = ffscripts[script];
1418 11172226 ffcdata* ffc = get_ffc(index);
1419
1420
2/2
✓ Branch 0 taken 11145571 times.
✓ Branch 1 taken 26655 times.
11172226 if (!data.initialized)
1421 {
1422 26655 got_initialized = true;
1423 26655 mapscr* scr = get_scr(ffc->screen_spawned);
1424 26655 memcpy(ri->d, scr->ffcs[index % 128].initd, 8 * sizeof(int32_t));
1425 26655 data.initialized = true;
1426 26655 }
1427
1428
2/2
✓ Branch 0 taken 1644354 times.
✓ Branch 1 taken 9527872 times.
11172226 ri->ffcref = ZScriptVersion::ffcRefIsSpriteId() ? ffc->getUID() : index;
1429 11172226 ri->screenref = ffc->screen_spawned;
1430 }
1431 11172226 break;
1432
1433 case ScriptType::NPC:
1434 {
1435 enemy *spr = (enemy*)guys.getByUID(index);
1436 curscript = guyscripts[script];
1437
1438 if (!data.initialized)
1439 {
1440 got_initialized = true;
1441 memcpy(ri->d, spr->initD, 8 * sizeof(int32_t));
1442 data.initialized = 1;
1443 }
1444
1445 ri->guyref = index;
1446 ri->screenref = spr->screen_spawned;
1447 }
1448 break;
1449
1450 case ScriptType::Lwpn:
1451 {
1452 212924 weapon *spr = (weapon*)Lwpns.getByUID(index);
1453 212924 curscript = lwpnscripts[script];
1454
1455
2/2
✓ Branch 0 taken 150555 times.
✓ Branch 1 taken 62369 times.
212924 if (!data.initialized)
1456 {
1457 62369 got_initialized = true;
1458 62369 memcpy(ri->d, spr->weap_initd, 8 * sizeof(int32_t));
1459 62369 data.initialized = 1;
1460 62369 }
1461
1462 212924 ri->lwpn = index;
1463 212924 ri->screenref = spr->screen_spawned;
1464 }
1465 212924 break;
1466
1467 case ScriptType::Ewpn:
1468 {
1469 147334 weapon *spr = (weapon*)Ewpns.getByUID(index);
1470 147334 curscript = ewpnscripts[script];
1471
1472
2/2
✓ Branch 0 taken 145713 times.
✓ Branch 1 taken 1621 times.
147334 if (!data.initialized)
1473 {
1474 1621 got_initialized = true;
1475 1621 memcpy(ri->d, spr->weap_initd, 8 * sizeof(int32_t));
1476 1621 data.initialized = 1;
1477 1621 }
1478
1479 147334 ri->ewpn = index;
1480 147334 ri->screenref = spr->screen_spawned;
1481 }
1482 147334 break;
1483
1484 case ScriptType::ItemSprite:
1485 {
1486 7460 item *spr = (item*)items.getByUID(index);
1487 7460 curscript = itemspritescripts[script];
1488
1489
2/2
✓ Branch 0 taken 7210 times.
✓ Branch 1 taken 250 times.
7460 if (!data.initialized)
1490 {
1491 250 got_initialized = true;
1492 250 memcpy(ri->d, spr->initD, 8 * sizeof(int32_t));
1493 250 data.initialized = 1;
1494 250 }
1495
1496 7460 ri->itemref = index;
1497 7460 ri->screenref = spr->screen_spawned;
1498 }
1499 7460 break;
1500
1501 case ScriptType::Item:
1502 {
1503 15539 int32_t i = index;
1504 15539 int32_t new_i = 0;
1505
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 15232 times.
15539 bool collect = ( ( i < 1 ) || (i == COLLECT_SCRIPT_ITEM_ZERO) );
1506
3/4
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 15232 times.
✓ Branch 2 taken 307 times.
✗ Branch 3 not taken.
15539 new_i = ( collect ) ? (( i != COLLECT_SCRIPT_ITEM_ZERO ) ? (i * -1) : 0) : i;
1507
1508 15539 curscript = itemscripts[script];
1509
1510
2/2
✓ Branch 0 taken 13490 times.
✓ Branch 1 taken 2049 times.
15539 if (!data.initialized)
1511 {
1512 2049 got_initialized = true;
1513
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 1742 times.
2049 memcpy(ri->d, ( collect ) ? itemsbuf[new_i].initiald : itemsbuf[i].initiald, 8 * sizeof(int32_t));
1514 2049 data.initialized = true;
1515 2049 }
1516
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 15232 times.
15539 ri->idata = ( collect ) ? new_i : i; //'this' pointer
1517 }
1518 15539 break;
1519
1520 case ScriptType::Global:
1521 {
1522 11113138 curscript = globalscripts[script];
1523
2/2
✓ Branch 0 taken 11110083 times.
✓ Branch 1 taken 3055 times.
11113138 if (!data.initialized)
1524 {
1525 3055 got_initialized = true;
1526 3055 data.initialized = 1;
1527
1528 // If this compat QR is on, scripts can run before ~Init and set global variables.
1529 // Before overwriting them with 0, get rid of object references held by global variables.
1530
6/6
✓ Branch 0 taken 2560 times.
✓ Branch 1 taken 495 times.
✓ Branch 2 taken 1009 times.
✓ Branch 3 taken 1551 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 991 times.
3055 if (get_qr(qr_OLD_INIT_SCRIPT_TIMING) && ZScriptVersion::gc() && script == GLOBAL_SCRIPT_INIT)
1531 {
1532
2/2
✓ Branch 0 taken 18432 times.
✓ Branch 1 taken 18 times.
18450 for (int i = 0; i < MAX_SCRIPT_REGISTERS; i++)
1533 18432 script_object_ref_dec(game->global_d[i]);
1534 18 }
1535 3055 }
1536 }
1537 11113138 break;
1538
1539 case ScriptType::Generic:
1540 {
1541 2141119 user_genscript& scr = user_genscript::get(script);
1542 2141119 curscript = genericscripts[script];
1543 2141119 scr.waitevent = false;
1544
2/2
✓ Branch 0 taken 2140539 times.
✓ Branch 1 taken 580 times.
2141119 if(!data.initialized)
1545 {
1546 580 got_initialized = true;
1547 580 scr.initd.copy_to(ri->d, 8);
1548 580 data.initialized = true;
1549 580 }
1550 2141119 ri->genericdataref = script;
1551 }
1552 2141119 break;
1553
1554 case ScriptType::GenericFrozen:
1555 {
1556 1542 user_genscript& scr = user_genscript::get(script);
1557 1542 curscript = genericscripts[script];
1558
2/2
✓ Branch 0 taken 1532 times.
✓ Branch 1 taken 10 times.
1542 if(!data.initialized)
1559 {
1560 10 got_initialized = true;
1561 10 scr.initd.copy_to(ri->d, 8);
1562 10 data.initialized = true;
1563 10 }
1564 1542 ri->genericdataref = script;
1565 }
1566 1542 break;
1567
1568 case ScriptType::Hero:
1569 {
1570 1330339 curscript = playerscripts[script];
1571 1330339 ri->screenref = hero_screen;
1572
2/2
✓ Branch 0 taken 1329874 times.
✓ Branch 1 taken 465 times.
1330339 if (!data.initialized)
1573 {
1574 465 got_initialized = true;
1575 465 data.initialized = 1;
1576 465 }
1577 }
1578 1330339 break;
1579
1580 case ScriptType::DMap:
1581 {
1582 74519 curscript = dmapscripts[script];
1583 74519 ri->dmapsref = index;
1584 //how do we clear initialised on dmap change?
1585
2/2
✓ Branch 0 taken 74425 times.
✓ Branch 1 taken 94 times.
74519 if ( !data.initialized )
1586 {
1587 94 got_initialized = true;
1588
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 94 times.
846 for ( int32_t q = 0; q < 8; q++ )
1589 {
1590 752 ri->d[q] = DMaps[ri->dmapsref].initD[q];// * 10000;
1591 752 }
1592 94 data.initialized = true;
1593 94 }
1594 }
1595 74519 break;
1596
1597 case ScriptType::OnMap:
1598 {
1599 114 curscript = dmapscripts[script];
1600 114 ri->dmapsref = index;
1601
2/2
✓ Branch 0 taken 111 times.
✓ Branch 1 taken 3 times.
114 if (!data.initialized)
1602 {
1603 3 got_initialized = true;
1604
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 3 times.
27 for ( int32_t q = 0; q < 8; q++ )
1605 {
1606 24 ri->d[q] = DMaps[ri->dmapsref].onmap_initD[q];
1607 24 }
1608 3 data.initialized = true;
1609 3 }
1610 }
1611 114 break;
1612
1613 case ScriptType::ScriptedActiveSubscreen:
1614 {
1615 12244 curscript = dmapscripts[script];
1616 12244 ri->dmapsref = index;
1617
2/2
✓ Branch 0 taken 12203 times.
✓ Branch 1 taken 41 times.
12244 if (!data.initialized)
1618 {
1619 41 got_initialized = true;
1620
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 41 times.
369 for ( int32_t q = 0; q < 8; q++ )
1621 {
1622 328 ri->d[q] = DMaps[ri->dmapsref].sub_initD[q];
1623 328 }
1624 41 data.initialized = true;
1625 41 }
1626 }
1627 12244 break;
1628
1629 case ScriptType::ScriptedPassiveSubscreen:
1630 {
1631 1402 curscript = dmapscripts[script];
1632 1402 ri->dmapsref = index;
1633
2/2
✓ Branch 0 taken 1400 times.
✓ Branch 1 taken 2 times.
1402 if (!data.initialized)
1634 {
1635 2 got_initialized = true;
1636
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 2 times.
18 for ( int32_t q = 0; q < 8; q++ )
1637 {
1638 16 ri->d[q] = DMaps[ri->dmapsref].sub_initD[q];
1639 16 }
1640 2 data.initialized = true;
1641 2 }
1642 }
1643 1402 break;
1644 case ScriptType::EngineSubscreen:
1645 {
1646 15162 curscript = subscreenscripts[script];
1647 15162 ri->subdataref = get_subref(-1, sstACTIVE);
1648 15450 auto [ptr,_ty] = load_subdata(ri->subdataref);
1649
1650
3/4
✓ Branch 0 taken 15162 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15126 times.
✓ Branch 3 taken 36 times.
15162 if (ptr && !data.initialized)
1651 {
1652 36 got_initialized = true;
1653
2/2
✓ Branch 0 taken 288 times.
✓ Branch 1 taken 36 times.
324 for ( int32_t q = 0; q < 8; q++ )
1654 {
1655 288 ri->d[q] = ptr->initd[q];
1656 288 }
1657 36 data.initialized = true;
1658 36 }
1659 }
1660 15162 break;
1661
1662 case ScriptType::Screen:
1663 {
1664 56311 curscript = screenscripts[script];
1665
1666
2/2
✓ Branch 0 taken 56192 times.
✓ Branch 1 taken 119 times.
56311 if (!data.initialized)
1667 {
1668 119 got_initialized = true;
1669 119 mapscr* scr = get_scr(index);
1670
2/2
✓ Branch 0 taken 952 times.
✓ Branch 1 taken 119 times.
1071 for ( int32_t q = 0; q < 8; q++ )
1671 {
1672 952 ri->d[q] = scr->screeninitd[q];// * 10000;
1673 952 }
1674 119 data.initialized = true;
1675 119 }
1676
1677 56311 ri->screenref = index;
1678 }
1679 56311 break;
1680
1681 case ScriptType::Combo:
1682 {
1683 368512 curscript = comboscripts[script];
1684
1685 368512 rpos_t rpos = combopos_ref_to_rpos(index);
1686 368512 int32_t lyr = combopos_ref_to_layer(index);
1687 368512 auto rpos_handle = get_rpos_handle(rpos, lyr);
1688 368512 int32_t id = rpos_handle.data();
1689
2/2
✓ Branch 0 taken 360187 times.
✓ Branch 1 taken 8325 times.
368512 if (!data.initialized)
1690 {
1691 8325 got_initialized = true;
1692 8325 memset(ri->d, 0, 8 * sizeof(int32_t));
1693
2/2
✓ Branch 0 taken 66600 times.
✓ Branch 1 taken 8325 times.
74925 for ( int32_t q = 0; q < 8; q++ )
1694 66600 ri->d[q] = combobuf[id].initd[q];
1695 8325 data.initialized = true;
1696 8325 }
1697
1698 368512 ri->combosref = id; //'this' pointer
1699 368512 ri->comboposref = index; //used for X(), Y(), Layer(), and so forth.
1700 368512 ri->screenref = rpos_handle.screen;
1701 368512 break;
1702 }
1703 }
1704
1705
2/2
✓ Branch 0 taken 26564211 times.
✓ Branch 1 taken 105674 times.
26669885 if (got_initialized)
1706 105674 ri->pc = curscript->pc;
1707
1708 26669885 return got_initialized;
1709 }
1710
1711 643317972 static ffcdata *ResolveFFCWithID(ffc_id_t id)
1712 {
1713
2/2
✓ Branch 0 taken 231 times.
✓ Branch 1 taken 643317741 times.
643317972 if (BC::checkFFC(id) != SH::_NoError)
1714 231 return nullptr;
1715
1716 643317741 ffcdata* ffc = get_ffc(id);
1717
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 643317741 times.
643317741 if (!ffc)
1718 scripting_log_error_with_context("Invalid ffc using ID = {}", id);
1719
1720 643317741 return ffc;
1721 643317972 }
1722
1723 646324090 static ffcdata *ResolveFFC(int32_t ffcref)
1724 {
1725
2/2
✓ Branch 0 taken 6374648 times.
✓ Branch 1 taken 639949442 times.
646324090 if (ZScriptVersion::ffcRefIsSpriteId())
1726 6374648 return ResolveSprite<ffcdata>(ffcref, "ffc");
1727
1728 639949442 return ResolveFFCWithID(ffcref);
1729 646324090 }
1730
1731 528 static mapscr* ResolveMapdataScr(int32_t mapref)
1732 {
1733 528 auto mapdata = decode_mapdata_ref(mapref);
1734
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 528 times.
528 if (!mapdata.scr)
1735 scripting_log_error_with_context("mapdata id is invalid: {}", mapref);
1736 528 return mapdata.scr;
1737 }
1738
1739 static rpos_handle_t ResolveMapdataPos(int32_t mapref, int pos)
1740 {
1741 auto mapdata = decode_mapdata_ref(mapref);
1742 if (!mapdata.scr)
1743 {
1744 scripting_log_error_with_context("mapdata id is invalid: {}", mapref);
1745 return rpos_handle_t{};
1746 }
1747
1748 return mapdata.resolve_pos(pos);
1749 }
1750
1751 86699825 int mapdata::max_pos()
1752 {
1753
2/2
✓ Branch 0 taken 69348879 times.
✓ Branch 1 taken 17350946 times.
86699825 if (type == mapdata_type::TemporaryCurrentRegion)
1754 69348879 return (int)region_max_rpos;
1755
1756
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17350946 times.
17350946 if (type == mapdata_type::TemporaryScrollingRegion)
1757 return (int)scrolling_region.screen_count * 176 - 1;
1758
1759 17350946 return 175;
1760 86699825 }
1761
1762 86699825 rpos_handle_t mapdata::resolve_pos(int pos)
1763 {
1764
3/4
✓ Branch 0 taken 85433327 times.
✓ Branch 1 taken 1266498 times.
✓ Branch 2 taken 85433327 times.
✗ Branch 3 not taken.
86699825 if (!screenscrolling && scrolling())
1765 {
1766 int32_t mapref = create_mapdata_temp_ref(type, screen, layer);
1767 scripting_log_error_with_context("mapdata id is invalid: {} - screen is not scrolling right now", mapref);
1768 return rpos_handle_t{};
1769 }
1770
1771 // mapdata loaded via `Game->LoadTempScreen(layer)` have access to the entire region.
1772
2/2
✓ Branch 0 taken 69348879 times.
✓ Branch 1 taken 17350946 times.
86699825 if (type == mapdata_type::TemporaryCurrentRegion)
1773 {
1774 69348879 rpos_t rpos = (rpos_t)pos;
1775
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69348879 times.
69348879 if (BC::checkComboRpos(rpos) != SH::_NoError)
1776 return rpos_handle_t{};
1777
1778 69348879 return get_rpos_handle(rpos, layer);
1779 }
1780
1781 // mapdata loaded via `Game->LoadScrollingScreen(layer)` have access to the entire scrolling region.
1782
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17350946 times.
17350946 if (type == mapdata_type::TemporaryScrollingRegion)
1783 {
1784 rpos_t rpos = (rpos_t)pos;
1785 rpos_t max = (rpos_t)(scrolling_region.screen_count * 176 - 1);
1786 if (BC::checkBoundsRpos(rpos, (rpos_t)0, max) != SH::_NoError)
1787 return rpos_handle_t{};
1788
1789 int origin_screen = scrolling_region.origin_screen;
1790 int origin_screen_x = origin_screen % 16;
1791 int origin_screen_y = origin_screen / 16;
1792 int scr_index = static_cast<int32_t>(rpos) / 176;
1793 int scr_x = origin_screen_x + scr_index%cur_region.screen_width;
1794 int scr_y = origin_screen_y + scr_index/cur_region.screen_width;
1795 int screen = map_scr_xy_to_index(scr_x, scr_y);
1796 mapscr* scr = FFCore.ScrollingScreensAll[screen * 7 + layer];
1797
1798 return {scr, screen, layer, rpos, RPOS_TO_POS(rpos)};
1799 }
1800
1801 // Otherwise, access is limited to just one screen.
1802
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17350946 times.
17350946 if (BC::checkComboPos(pos) != SH::_NoError)
1803 return rpos_handle_t{};
1804
1805
1/2
✓ Branch 0 taken 17350946 times.
✗ Branch 1 not taken.
17350946 if (type == mapdata_type::CanonicalScreen)
1806 17350946 return {scr, screen, 0, (rpos_t)pos, pos};
1807
1808 if (scrolling())
1809 {
1810 if (!scr->is_valid())
1811 return rpos_handle_t{};
1812
1813 return {scr, screen, layer, (rpos_t)pos, pos};
1814 }
1815
1816 rpos_t rpos = POS_TO_RPOS(pos, screen);
1817 if (BC::checkComboRpos(rpos) != SH::_NoError)
1818 return rpos_handle_t{};
1819
1820 return {scr, screen, layer, rpos, pos};
1821 86699825 }
1822
1823 1557619 ffc_handle_t mapdata::resolve_ffc_handle(int index)
1824 {
1825 1557619 index -= 1;
1826
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1557619 times.
1557619 if (BC::checkMapdataFFC(index) != SH::_NoError)
1827 return ffc_handle_t{};
1828
1829 1557619 int screen_index_offset = 0;
1830
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1557619 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1557619 if (current() && layer == 0)
1831 screen_index_offset = get_region_screen_offset(screen);
1832
1833 1557619 return *scr->getFFCHandle(index, screen_index_offset);
1834 1557619 }
1835
1836 1557411 ffcdata* mapdata::resolve_ffc(int index)
1837 {
1838 1557411 return resolve_ffc_handle(index).ffc;
1839 }
1840
1841 2045 static ffc_handle_t ResolveMapdataFFC(int32_t mapref, int index)
1842 {
1843 2045 index -= 1;
1844
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2045 times.
2045 if (BC::checkMapdataFFC(index) != SH::_NoError)
1845 return ffc_handle_t{};
1846
1847 2045 auto result = decode_mapdata_ref(mapref);
1848
1/2
✓ Branch 0 taken 2045 times.
✗ Branch 1 not taken.
2045 if (!result.scr)
1849 {
1850 scripting_log_error_with_context("mapdata id is invalid: {}", mapref);
1851 return ffc_handle_t{};
1852 }
1853
1854 2045 int screen_index_offset = 0;
1855
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2045 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2045 if (result.current() && result.layer == 0)
1856 screen_index_offset = get_region_screen_offset(result.screen);
1857
1858 2045 return *result.scr->getFFCHandle(index, screen_index_offset);
1859 2045 }
1860
1861 int32_t genscript_timing = SCR_TIMING_START_FRAME;
1862 static word max_valid_genscript;
1863
1864 213504 void user_genscript::clear()
1865 {
1866 213504 wait_atleast = true;
1867 213504 waituntil = SCR_TIMING_START_FRAME;
1868 213504 waitevent = false;
1869 213504 exitState = 0;
1870 213504 reloadState = 0;
1871 213504 eventstate = 0;
1872 213504 initd.clear();
1873 213504 data.clear();
1874 213504 quit();
1875 213504 }
1876 531 void user_genscript::launch()
1877 {
1878 531 quit();
1879 531 doscript() = true;
1880 531 wait_atleast = true;
1881 531 waituntil = SCR_TIMING_START_FRAME;
1882 531 waitevent = false;
1883 531 }
1884 214074 void user_genscript::quit()
1885 {
1886
1/2
✓ Branch 0 taken 214074 times.
✗ Branch 1 not taken.
214074 if(indx > -1)
1887 {
1888 214074 FFCore.destroyScriptableObject(ScriptType::Generic, indx);
1889 214074 }
1890 214074 _doscript = false;
1891 214074 }
1892 256150060 byte& user_genscript::doscript()
1893 {
1894 256150060 return _doscript;
1895 }
1896 512 byte const& user_genscript::doscript() const
1897 {
1898 512 return _doscript;
1899 }
1900
1901
1902 268901142 user_genscript& user_genscript::get(int ind)
1903 {
1904
3/4
✓ Branch 0 taken 268900724 times.
✓ Branch 1 taken 418 times.
✓ Branch 2 taken 268900724 times.
✗ Branch 3 not taken.
268901142 if(ind < 1 || ind >= NUMSCRIPTSGENERIC)
1905 418 ind = 0;
1906 268901142 user_scripts[ind].indx = ind;
1907 268901142 return user_scripts[ind];
1908 }
1909
3/4
✓ Branch 0 taken 208384 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 207977 times.
✓ Branch 3 taken 407 times.
208384 user_genscript user_genscript::user_scripts[NUMSCRIPTSGENERIC];
1910
1911 1494 void countGenScripts()
1912 {
1913 1494 max_valid_genscript = 0;
1914
2/2
✓ Branch 0 taken 763434 times.
✓ Branch 1 taken 1494 times.
764928 for(auto q = 1; q < NUMSCRIPTSGENERIC; ++q)
1915 {
1916
3/4
✓ Branch 0 taken 763434 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 760321 times.
✓ Branch 3 taken 3113 times.
763434 if(genericscripts[q] && genericscripts[q]->valid())
1917 3113 max_valid_genscript = q;
1918 763434 }
1919 1494 }
1920 43606 void timeExitAllGenscript(byte exState)
1921 {
1922
2/2
✓ Branch 0 taken 25924 times.
✓ Branch 1 taken 43606 times.
69530 for(auto q = 1; q <= max_valid_genscript; ++q)
1923 25924 user_genscript::get(q).timeExit(exState);
1924 43606 }
1925 466743 void throwGenScriptEvent(int32_t event)
1926 {
1927
2/2
✓ Branch 0 taken 133663 times.
✓ Branch 1 taken 466743 times.
600406 for(auto q = 1; q <= max_valid_genscript; ++q)
1928 {
1929 133663 user_genscript& scr = user_genscript::get(q);
1930
2/2
✓ Branch 0 taken 76759 times.
✓ Branch 1 taken 56904 times.
133663 if(!scr.doscript()) continue;
1931
2/2
✓ Branch 0 taken 73959 times.
✓ Branch 1 taken 2800 times.
76759 if(!genericscripts[q]->valid()) continue;
1932
2/2
✓ Branch 0 taken 41495 times.
✓ Branch 1 taken 32464 times.
73959 if(!scr.waitevent) continue;
1933
2/2
✓ Branch 0 taken 3068 times.
✓ Branch 1 taken 38427 times.
41495 if(scr.eventstate & (1<<event))
1934 {
1935 3068 auto& data = get_script_engine_data(ScriptType::Generic, q);
1936 3068 data.ref.d[rEXP1] = event*10000;
1937 3068 scr.waitevent = false;
1938
1939 //Run the script!
1940 3068 ZScriptVersion::RunScript(ScriptType::Generic, q, q);
1941 3068 }
1942 41495 }
1943 466743 }
1944
1945 217 void load_genscript(const gamedata& gd)
1946 {
1947
2/2
✓ Branch 0 taken 111104 times.
✓ Branch 1 taken 217 times.
111321 for(size_t q = 0; q < NUMSCRIPTSGENERIC; ++q)
1948 {
1949 111104 user_genscript& gen = user_genscript::get(q);
1950 111104 gen.clear();
1951 111104 gen.doscript() = gd.gen_doscript.get(q);
1952 111104 gen.exitState = gd.gen_exitState[q];
1953 111104 gen.reloadState = gd.gen_reloadState[q];
1954 111104 gen.eventstate = gd.gen_eventstate[q];
1955 111104 gen.initd = gd.gen_initd[q];
1956 111104 gen.data = gd.gen_data[q];
1957 111104 }
1958 217 }
1959 200 void load_genscript(const zinitdata& zd)
1960 {
1961
2/2
✓ Branch 0 taken 102400 times.
✓ Branch 1 taken 200 times.
102600 for(size_t q = 0; q < NUMSCRIPTSGENERIC; ++q)
1962 {
1963 102400 user_genscript& gen = user_genscript::get(q);
1964 102400 gen.clear();
1965 102400 gen.doscript() = zd.gen_doscript.get(q);
1966 102400 gen.exitState = zd.gen_exitState[q];
1967 102400 gen.reloadState = zd.gen_reloadState[q];
1968 102400 gen.eventstate = zd.gen_eventstate[q];
1969 102400 gen.initd = zd.gen_initd[q];
1970 102400 gen.data = zd.gen_data[q];
1971 102400 }
1972 200 }
1973
1974 1 void save_genscript(gamedata& gd)
1975 {
1976
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 1 times.
513 for(size_t q = 0; q < NUMSCRIPTSGENERIC; ++q)
1977 {
1978 512 user_genscript const& gen = user_genscript::get(q);
1979 512 gd.gen_doscript.set(q, gen.doscript());
1980 512 gd.gen_exitState[q] = gen.exitState;
1981 512 gd.gen_reloadState[q] = gen.reloadState;
1982 512 gd.gen_eventstate[q] = gen.eventstate;
1983 512 gd.gen_initd[q] = gen.initd;
1984 512 gd.gen_data[q] = gen.data;
1985 512 }
1986 1 }
1987
1988 591384440 void FFScript::runGenericPassiveEngine(int32_t scrtm)
1989 {
1990
2/2
✓ Branch 0 taken 19589349 times.
✓ Branch 1 taken 571795091 times.
591384440 if(!max_valid_genscript) return; //No generic scripts in the quest!
1991 19589349 bool init = (scrtm == SCR_TIMING_INIT);
1992
2/2
✓ Branch 0 taken 106 times.
✓ Branch 1 taken 19589243 times.
19589349 if(!init)
1993 {
1994
2/2
✓ Branch 0 taken 297552 times.
✓ Branch 1 taken 19291691 times.
19589243 if(genscript_timing != scrtm)
1995 {
1996
2/2
✓ Branch 0 taken 1661258 times.
✓ Branch 1 taken 297552 times.
1958810 while(genscript_timing != scrtm)
1997 1661258 runGenericPassiveEngine(genscript_timing);
1998 297552 }
1999 19589243 }
2000
2/2
✓ Branch 0 taken 255770951 times.
✓ Branch 1 taken 19589349 times.
275360300 for(auto q = 1; q <= max_valid_genscript; ++q)
2001 {
2002 255770951 user_genscript& scr = user_genscript::get(q);
2003
2/2
✓ Branch 0 taken 131922898 times.
✓ Branch 1 taken 123848053 times.
255770951 if(!scr.doscript()) continue;
2004
2/2
✓ Branch 0 taken 3460755 times.
✓ Branch 1 taken 128462143 times.
131922898 if(!genericscripts[q]->valid()) continue;
2005
2/2
✓ Branch 0 taken 75940592 times.
✓ Branch 1 taken 52521551 times.
128462143 if(scr.waitevent) continue;
2006
8/8
✓ Branch 0 taken 52521491 times.
✓ Branch 1 taken 60 times.
✓ Branch 2 taken 42172947 times.
✓ Branch 3 taken 10348544 times.
✓ Branch 4 taken 42172443 times.
✓ Branch 5 taken 504 times.
✓ Branch 6 taken 40034955 times.
✓ Branch 7 taken 2137488 times.
52521551 if(!init && (scr.waituntil > scrtm || (!scr.wait_atleast && scr.waituntil != scrtm)))
2007 50383499 continue;
2008
2009 //Run the script!
2010 2138052 ZScriptVersion::RunScript(ScriptType::Generic, q, q);
2011 2138052 }
2012
4/4
✓ Branch 0 taken 19589243 times.
✓ Branch 1 taken 106 times.
✓ Branch 2 taken 19087246 times.
✓ Branch 3 taken 501997 times.
19589349 if(init || genscript_timing >= SCR_TIMING_END_FRAME)
2013 502103 genscript_timing = SCR_TIMING_START_FRAME;
2014 19087246 else ++genscript_timing;
2015 591384440 }
2016
2017 13360 void FFScript::initZScriptDMapScripts()
2018 {
2019
2/4
✓ Branch 0 taken 13360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13360 times.
✗ Branch 3 not taken.
13360 scriptEngineDatas[{ScriptType::DMap, 0}] = ScriptEngineData();
2020
2/4
✓ Branch 0 taken 13360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13360 times.
✗ Branch 3 not taken.
13360 scriptEngineDatas[{ScriptType::ScriptedPassiveSubscreen, 0}] = ScriptEngineData();
2021 13360 }
2022
2023 1357 void FFScript::initZScriptSubscreenScript()
2024 {
2025
2/4
✓ Branch 0 taken 1357 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1357 times.
✗ Branch 3 not taken.
1357 scriptEngineDatas[{ScriptType::EngineSubscreen, 0}] = ScriptEngineData();
2026 1357 }
2027 13297 void FFScript::initZScriptScriptedActiveSubscreen()
2028 {
2029
2/4
✓ Branch 0 taken 13297 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13297 times.
✗ Branch 3 not taken.
13297 scriptEngineDatas[{ScriptType::ScriptedActiveSubscreen, 0}] = ScriptEngineData();
2030 13297 }
2031
2032 3 void FFScript::initZScriptOnMapScript()
2033 {
2034
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 scriptEngineDatas[{ScriptType::OnMap, 0}] = ScriptEngineData();
2035 3 }
2036
2037 2687 void FFScript::initZScriptHeroScripts()
2038 {
2039
2/4
✓ Branch 0 taken 2687 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2687 times.
✗ Branch 3 not taken.
2687 scriptEngineDatas[{ScriptType::Hero, 0}] = ScriptEngineData();
2040 2687 }
2041
2042 2395 void FFScript::initZScriptItemScripts()
2043 {
2044
2/2
✓ Branch 0 taken 613120 times.
✓ Branch 1 taken 2395 times.
615515 for ( int32_t q = 0; q < 256; q++ )
2045 {
2046 613120 auto& data = get_script_engine_data(ScriptType::Item, q);
2047 613120 data.reset();
2048
2/2
✓ Branch 0 taken 613118 times.
✓ Branch 1 taken 2 times.
613120 data.doscript = (itemsbuf[q].flags&item_passive_script) && game->item[q];
2049 613120 }
2050
2051
2/2
✓ Branch 0 taken 613120 times.
✓ Branch 1 taken 2395 times.
615515 for ( int32_t q = -256; q < 0; q++ )
2052 {
2053 613120 auto& data = get_script_engine_data(ScriptType::Item, q);
2054 613120 data.reset();
2055 613120 data.doscript = 0;
2056 613120 }
2057 2395 }
2058
2059 2658892 int get_mouse_state(int index)
2060 {
2061 2658892 int value = 0;
2062
1/2
✓ Branch 0 taken 2658892 times.
✗ Branch 1 not taken.
2658892 if (replay_is_replaying())
2063 {
2064 2658892 value = replay_get_mouse(index);
2065 2658892 }
2066 else if (index == 0)
2067 {
2068 value = script_mouse_x;
2069 }
2070 else if (index == 1)
2071 {
2072 value = script_mouse_y;
2073 }
2074 else if (index == 2)
2075 {
2076 value = script_mouse_z;
2077 }
2078 else if (index == 3)
2079 {
2080 value = script_mouse_b;
2081 }
2082
2083
2/2
✓ Branch 0 taken 2657296 times.
✓ Branch 1 taken 1596 times.
2658892 if (replay_is_recording())
2084 {
2085 1596 replay_set_mouse(index, value);
2086 1596 }
2087
2088 2658892 return value;
2089 }
2090
2091 ///---------------------------------------------//
2092 // Array Helper Functions //
2093 ///---------------------------------------------//
2094
2095 #define ZCARRAY_MAX_SIZE 214748
2096
2097 303070156 size_t ArrayH::getSize(const int32_t ptr)
2098 {
2099 303070156 ArrayManager am(ptr);
2100 303070156 return am.size();
2101 }
2102
2103 //Can't you get the std::string and then check its length?
2104 int32_t ArrayH::strlen(const int32_t ptr)
2105 {
2106 ArrayManager am(ptr);
2107 if (am.invalid() || am.size() == 0)
2108 return -1;
2109
2110 word count;
2111 size_t sz = am.size();
2112 for(count = 0; BC::checkUserArrayIndex(count, sz) == _NoError
2113 && am.get(count) != '\0'; count++);
2114
2115 return count;
2116 }
2117
2118 //Returns values of a zscript array as an std::string.
2119 12210139 void ArrayH::getString(const int32_t ptr, string &str, dword num_chars, dword offset)
2120 {
2121 12210139 ArrayManager am(ptr);
2122
2123
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 12210134 times.
12210139 if(am.invalid())
2124 {
2125 5 str.clear();
2126 5 return;
2127 }
2128
2129 12210134 str.clear();
2130 12210134 size_t sz = am.size();
2131
5/6
✓ Branch 0 taken 173076690 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12210134 times.
✓ Branch 3 taken 160866556 times.
✓ Branch 4 taken 12210134 times.
✓ Branch 5 taken 160866556 times.
173076690 for(word i = offset; BC::checkUserArrayIndex(i, sz) == _NoError && am.get(i) != '\0' && num_chars != 0; i++)
2132 {
2133 160866556 int32_t c = am.get(i) / 10000;
2134
1/2
✓ Branch 0 taken 160866556 times.
✗ Branch 1 not taken.
160866556 if(byte(c) != c)
2135 {
2136 Z_scripterrlog("Illegal char value (%d) at position [%d] in string pointer %d\n", c, i, ptr);
2137 Z_scripterrlog("Value of invalid char will overflow.\n");
2138 }
2139 160866556 str += byte(c);
2140 160866556 --num_chars;
2141 160866556 }
2142 12210139 }
2143
2144 //Used for issues where reading the ZScript array floods the console with errors 'Accessing array index [12] size of 12.
2145 //Happens with Quad3D and some other functions, and I have no clue why. -Z ( 28th April, 2019 )
2146 //Like getString but for an array of longs instead of chars. *(arrayPtr is not checked for validity)
2147 void ArrayH::getValues2(const int32_t ptr, int32_t* arrayPtr, dword num_values, dword offset) //a hack -Z
2148 {
2149 ArrayManager am(ptr);
2150
2151 if(am.invalid())
2152 return;
2153
2154 size_t sz = am.size();
2155 for(word i = offset; BC::checkUserArrayIndex(i, sz+1) == _NoError && num_values != 0; i++)
2156 {
2157 arrayPtr[i] = (am.get(i) / 10000);
2158 num_values--;
2159 }
2160 }
2161
2162 //Like getString but for an array of longs instead of chars. *(arrayPtr is not checked for validity)
2163 1080 void ArrayH::getValues(const int32_t ptr, int32_t* arrayPtr, dword num_values, dword offset)
2164 {
2165 1080 ArrayManager am(ptr);
2166
2167
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1080 times.
1080 if (am.invalid())
2168 return;
2169 1080 size_t sz = am.size();
2170
4/4
✓ Branch 0 taken 1080 times.
✓ Branch 1 taken 12960 times.
✓ Branch 2 taken 1080 times.
✓ Branch 3 taken 12960 times.
14040 for(word i = offset; num_values != 0 && BC::checkUserArrayIndex(i, sz) == _NoError; i++)
2171 {
2172 12960 arrayPtr[i] = (am.get(i) / 10000);
2173 12960 num_values--;
2174 12960 }
2175 1080 }
2176
2177 2 void ArrayH::copyValues(const int32_t ptr, const int32_t ptr2)
2178 {
2179 2 ArrayManager am1(ptr), am2(ptr2);
2180
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if(am1.invalid() || am2.invalid())
2181 return;
2182
2183 2 int sz = std::min(am1.size(),am2.size());
2184
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 for (int i = 0; i < sz; i++)
2185 {
2186 4 am1.set(i,am2.get(i));
2187 4 }
2188 2 }
2189 //Get element from array
2190 1358553125 INLINE int32_t ArrayH::getElement(const int32_t ptr, int32_t offset, const bool neg)
2191 {
2192 1358553125 ArrayManager am(ptr,neg);
2193 1358553125 return am.get(offset);
2194 }
2195
2196 //Set element in array
2197 665952088 INLINE void ArrayH::setElement(const int32_t ptr, int32_t offset, const int32_t value, const bool neg)
2198 {
2199 665952088 ArrayManager am(ptr,neg);
2200 665952088 am.set(offset,value);
2201 665952088 }
2202
2203 3240018 int32_t ArrayH::setArray(const int32_t ptr, string const& s2, bool resize)
2204 {
2205 3240018 ArrayManager am(ptr);
2206
2207
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3240018 times.
3240018 if (am.invalid())
2208 return _InvalidPointer;
2209
2210 size_t i;
2211
2212
3/4
✓ Branch 0 taken 3240018 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3227226 times.
✓ Branch 3 taken 12792 times.
3240018 if(am.can_resize() && resize)
2213 12792 am.resize_min(s2.size()+1);
2214
2215 3240018 size_t sz = am.size();
2216
2/2
✓ Branch 0 taken 43420898 times.
✓ Branch 1 taken 3239949 times.
46660847 for(i = 0; i < s2.size(); i++)
2217 {
2218
2/2
✓ Branch 0 taken 43420829 times.
✓ Branch 1 taken 69 times.
43420898 if(i >= sz)
2219 {
2220 69 am.set(sz-1,'\0');
2221 69 return _Overflow;
2222 }
2223
2224
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43420829 times.
43420829 if(BC::checkUserArrayIndex(i, sz) == _NoError)
2225 43420829 am.set(i,s2[i] * 10000);
2226 43420829 }
2227
2228
1/2
✓ Branch 0 taken 3239949 times.
✗ Branch 1 not taken.
3239949 if(BC::checkUserArrayIndex(i, sz) == _NoError)
2229 3239949 am.set(i,'\0');
2230
2231 3239949 return _NoError;
2232 3240018 }
2233
2234 2343653774 ArrayManager::ArrayManager(int32_t ptr, bool neg) : negAccess(neg)
2235 {
2236 2343653774 _invalid = false;
2237 2343653774 internal_array_id = {};
2238 2343653774 legacy_internal_id = 0;
2239
2240
2/2
✓ Branch 0 taken 65502679 times.
✓ Branch 1 taken 2278151095 times.
2343653774 if (ZScriptVersion::gc_arrays())
2241 {
2242
1/2
✓ Branch 0 taken 65502679 times.
✗ Branch 1 not taken.
65502679 if (auto* array = checkArray(ptr))
2243 {
2244
2/2
✓ Branch 0 taken 3194 times.
✓ Branch 1 taken 65499485 times.
65502679 if (array->internal_id.has_value())
2245 {
2246
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3192 times.
3194 if (array->internal_expired)
2247 {
2248 2 current_zasm_extra_context = scripting_get_zasm_register_context_string(array->internal_id->zasm_var);
2249
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 scripting_log_error_with_context("Invalid internal array: the object this array refers to has expired");
2250 2 _invalid = true;
2251 2 return;
2252 }
2253
2254 3192 aptr = nullptr;
2255 3192 internal_array_id = array->internal_id.value();
2256
1/2
✓ Branch 0 taken 3192 times.
✗ Branch 1 not taken.
3192 if (!zasm_array_supports(internal_array_id.zasm_var))
2257 {
2258 scripting_log_error_with_context("Invalid internal array id: {}", internal_array_id.zasm_var);
2259 _invalid = true;
2260 return;
2261 }
2262 3192 }
2263 else
2264 {
2265 65499485 aptr = &array->arr;
2266 }
2267 65502677 }
2268 else
2269 {
2270 aptr = &INVALIDARRAY;
2271 _invalid = true;
2272 }
2273
2274
1/2
✓ Branch 0 taken 65502677 times.
✗ Branch 1 not taken.
65502677 if (_invalid)
2275 scripting_log_error_with_context("Invalid pointer used as array: {}", ptr);
2276 65502677 return;
2277 }
2278
2279 2278151095 ptr /= 10000;
2280
2281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2278151095 times.
2278151095 if(ptr >= INTARR_OFFS)
2282 {
2283 aptr = nullptr;
2284 legacy_internal_id = ptr;
2285 if(legacy_sz_int_arr(ptr) < 0)
2286 _invalid = true;
2287 }
2288
2/2
✓ Branch 0 taken 2278150376 times.
✓ Branch 1 taken 719 times.
2278151095 else if(ptr == 0)
2289 {
2290 719 aptr = &INVALIDARRAY;
2291 719 _invalid = true;
2292 719 }
2293
2/2
✓ Branch 0 taken 2278150315 times.
✓ Branch 1 taken 61 times.
2278150376 else if(ptr < 0) //An object array?
2294 {
2295 61 int32_t objptr = -ptr;
2296 61 auto it = objectRAM.find(objptr);
2297
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 61 times.
61 if(it == objectRAM.end())
2298 {
2299 aptr = &INVALIDARRAY;
2300 _invalid = true;
2301 }
2302 61 else aptr = &(it->second);
2303 61 }
2304
2/2
✓ Branch 0 taken 1824655168 times.
✓ Branch 1 taken 453495147 times.
2278150315 else if(ptr >= NUM_ZSCRIPT_ARRAYS) //Then it's a global
2305 {
2306 1824655168 dword gptr = ptr - NUM_ZSCRIPT_ARRAYS;
2307
2308
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1824655168 times.
1824655168 if(gptr > game->globalRAM.size())
2309 {
2310 aptr = &INVALIDARRAY;
2311 _invalid = true;
2312 }
2313 1824655168 else aptr = &(game->globalRAM[gptr]);
2314 1824655168 }
2315 else
2316 {
2317
1/2
✓ Branch 0 taken 453495147 times.
✗ Branch 1 not taken.
453495147 if(!localRAM[ptr].Valid())
2318 {
2319 aptr = &INVALIDARRAY;
2320 _invalid = true;
2321 }
2322 453495147 else aptr = &(localRAM[ptr]);
2323 }
2324
2/2
✓ Branch 0 taken 2278150376 times.
✓ Branch 1 taken 719 times.
2278151095 if (_invalid)
2325 {
2326 719 scripting_log_error_with_context("Invalid pointer used as array: {}", ptr);
2327 719 }
2328 2343653774 }
2329 319148561 ArrayManager::ArrayManager(int32_t ptr) : ArrayManager(ptr,can_neg_array){}
2330
2331 1692510137 int32_t ArrayManager::get(int32_t indx) const
2332 {
2333
2/2
✓ Branch 0 taken 241 times.
✓ Branch 1 taken 1692509896 times.
1692510137 if(_invalid) return -10000;
2334
2/2
✓ Branch 0 taken 1692508482 times.
✓ Branch 1 taken 1414 times.
1692509896 if(aptr)
2335 {
2336 1692508482 int32_t sz = size();
2337
2/2
✓ Branch 0 taken 633486 times.
✓ Branch 1 taken 1691874996 times.
1692508482 if(BC::checkUserArrayIndex(indx, sz, negAccess) == SH::_NoError)
2338 {
2339
2/2
✓ Branch 0 taken 1691874800 times.
✓ Branch 1 taken 196 times.
1691874996 if(indx < 0)
2340 196 indx += sz; //[-1] becomes [size-1] -Em
2341 1691874996 return (*aptr)[indx];
2342 }
2343 633486 }
2344 else //internal special array
2345 {
2346
1/2
✓ Branch 0 taken 1414 times.
✗ Branch 1 not taken.
1414 if (ZScriptVersion::gc_arrays())
2347 1414 return zasm_array_get(internal_array_id.zasm_var, internal_array_id.ref, indx);
2348
2349 int32_t sz = size();
2350 if(sz >= 0 && BC::checkUserArrayIndex(indx, sz, negAccess) == SH::_NoError)
2351 {
2352 if(indx < 0)
2353 indx += sz; //[-1] becomes [size-1] -Em
2354 return legacy_get_int_arr(legacy_internal_id, indx);
2355 }
2356 }
2357 633486 return -10000;
2358 1692510137 }
2359
2360 715460476 void ArrayManager::set(int32_t indx, int32_t val)
2361 {
2362
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 715460474 times.
715460476 if(_invalid) return;
2363
2364
2/2
✓ Branch 0 taken 715460118 times.
✓ Branch 1 taken 356 times.
715460474 if(aptr)
2365 {
2366 715460118 int32_t sz = size();
2367
2/2
✓ Branch 0 taken 7298 times.
✓ Branch 1 taken 715452820 times.
715460118 if(BC::checkUserArrayIndex(indx, sz, negAccess) == SH::_NoError)
2368 {
2369
1/2
✓ Branch 0 taken 715452820 times.
✗ Branch 1 not taken.
715452820 if(indx < 0)
2370 indx += sz; //[-1] becomes [size-1] -Em
2371
2/2
✓ Branch 0 taken 715452541 times.
✓ Branch 1 taken 279 times.
715452820 if (aptr->HoldsObjects())
2372 {
2373 279 int id = (*aptr)[indx];
2374 279 script_object_ref_dec(id);
2375 279 }
2376 715452820 (*aptr)[indx] = val;
2377
2/2
✓ Branch 0 taken 715452541 times.
✓ Branch 1 taken 279 times.
715452820 if (aptr->HoldsObjects())
2378 279 script_object_ref_inc(val);
2379 715452820 }
2380 715460118 }
2381 else //internal special array
2382 {
2383
1/2
✓ Branch 0 taken 356 times.
✗ Branch 1 not taken.
356 if (ZScriptVersion::gc_arrays())
2384 {
2385 356 zasm_array_set(internal_array_id.zasm_var, internal_array_id.ref, indx, val);
2386 356 return;
2387 }
2388
2389 int32_t sz = size();
2390 if(sz >= 0 && BC::checkUserArrayIndex(indx, sz, negAccess) == SH::_NoError)
2391 {
2392 if(indx < 0)
2393 indx += sz; //[-1] becomes [size-1] -Em
2394 legacy_set_int_arr(legacy_internal_id, indx, val);
2395 }
2396 }
2397 715460476 }
2398
2399 2727062925 int32_t ArrayManager::size() const
2400 {
2401
2/2
✓ Branch 0 taken 473 times.
✓ Branch 1 taken 2727062452 times.
2727062925 if(_invalid) return -1;
2402
2/2
✓ Branch 0 taken 2727061032 times.
✓ Branch 1 taken 1420 times.
2727062452 if(aptr)
2403 2727061032 return aptr->Size();
2404 else // Internal special
2405 {
2406
1/2
✓ Branch 0 taken 1420 times.
✗ Branch 1 not taken.
1420 if (ZScriptVersion::gc_arrays())
2407 1420 return zasm_array_size(internal_array_id.zasm_var, internal_array_id.ref);
2408
2409 int32_t sz = legacy_sz_int_arr(legacy_internal_id);
2410 if(sz < 0)
2411 return -1;
2412 return sz;
2413 }
2414 2727062925 }
2415
2416 1153 bool ArrayManager::resize(size_t newsize)
2417 {
2418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1153 times.
1153 if(_invalid) return false;
2419
2/2
✓ Branch 0 taken 1151 times.
✓ Branch 1 taken 2 times.
1153 if(!aptr)
2420 {
2421 2 log_invalid_operation();
2422 2 return false;
2423 }
2424
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1148 times.
1151 if (aptr->HoldsObjects())
2425 {
2426
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 for (int i = newsize; i < aptr->Size(); i++)
2427 {
2428 3 auto id = (*aptr)[i];
2429 3 script_object_ref_dec(id);
2430 3 }
2431 3 }
2432 1151 aptr->Resize(newsize);
2433 1151 return true;
2434 1153 }
2435
2436 12792 bool ArrayManager::resize_min(size_t newsize)
2437 {
2438
2/2
✓ Branch 0 taken 12500 times.
✓ Branch 1 taken 292 times.
12792 if(size() >= newsize)
2439 12500 return true;
2440 292 return resize(newsize);
2441 12792 }
2442
2443 3800067 bool ArrayManager::can_resize()
2444 {
2445
2/4
✓ Branch 0 taken 3800067 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3800067 times.
✗ Branch 3 not taken.
3800067 if(_invalid || !aptr)
2446 return false;
2447 3800067 return true;
2448 3800067 }
2449
2450 15 bool ArrayManager::push(int32_t val, int indx)
2451 {
2452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if(_invalid) return false;
2453
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 if(!aptr)
2454 {
2455 log_invalid_operation();
2456 return false;
2457 }
2458
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if(aptr->Size() == ZCARRAY_MAX_SIZE)
2459 return false;
2460 15 aptr->Push(val,indx);
2461
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 12 times.
15 if (aptr->HoldsObjects())
2462 3 script_object_ref_inc(val);
2463 15 return true;
2464 15 }
2465
2466 3 int32_t ArrayManager::pop(int indx)
2467 {
2468
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(_invalid) return -10000;
2469
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!aptr)
2470 {
2471 log_invalid_operation();
2472 return -10000;
2473 }
2474
2475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (aptr->Empty())
2476 {
2477 scripting_log_error_with_context("Array had nothing to Pop!");
2478 return -10000;
2479 }
2480
2481 3 int32_t val = aptr->Pop(indx);
2482
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (aptr->HoldsObjects())
2483 3 script_object_ref_dec(val);
2484 3 return val;
2485 3 }
2486
2487 std::string ArrayManager::asString(std::function<char const*(int32_t)> formatter, const size_t& limit) const
2488 {
2489 if(_invalid) return "{ INVALID ARRAY }";
2490 std::ostringstream oss;
2491 oss << "{ ";
2492 size_t s = size();
2493 bool overflow = limit < s;
2494 if(overflow)
2495 s = limit;
2496
2497 for(auto q = 0; q < s; ++q)
2498 {
2499 oss << formatter(get(q));
2500 if (q + 1 < s)
2501 oss << ", ";
2502 }
2503 if (overflow)
2504 oss << ", ...";
2505 oss << " }";
2506 return oss.str();
2507 }
2508
2509 2 void ArrayManager::log_invalid_operation() const
2510 {
2511
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (internal_array_id.zasm_var)
2512 {
2513 2 current_zasm_extra_context = scripting_get_zasm_register_context_string(internal_array_id.zasm_var);
2514
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 scripting_log_error_with_context("Internal array not valid for this operation");
2515 2 }
2516 else
2517 {
2518 scripting_log_error_with_context("Internal array '{}' not valid for this operation", legacy_internal_id);
2519 }
2520 2 }
2521
2522 // Call only when the underlying engine object is being deleted. This deallocs script data, and
2523 // invalidates any internal array references that may remain.
2524 // Any script type given to this function must also be handled in
2525 // script_array::internal_array_id::matches.
2526 2279926 void FFScript::destroyScriptableObject(ScriptType scriptType, const int32_t UID)
2527 {
2528 2279926 FFCore.deallocateAllScriptOwned(scriptType, UID);
2529 2279926 FFCore.reset_script_engine_data(scriptType, UID);
2530 2279926 expire_internal_script_arrays(scriptType, UID);
2531 2279926 }
2532
2533 35190 void FFScript::destroyScriptableObjectsOfType(ScriptType scriptType)
2534 {
2535 35190 FFCore.deallocateAllScriptOwnedOfType(scriptType);
2536 35190 FFCore.clear_script_engine_data_of_type(scriptType);
2537 35190 expire_internal_script_arrays(scriptType);
2538 35190 }
2539
2540 2461666 void FFScript::deallocateAllScriptOwned(ScriptType scriptType, const int32_t UID)
2541 {
2542 2461666 std::vector<uint32_t> ids_to_clear;
2543
8/14
✓ Branch 0 taken 2461666 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2461666 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2461666 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 51965349 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 49503683 times.
✓ Branch 9 taken 2461666 times.
✓ Branch 10 taken 49503683 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 49503683 times.
✗ Branch 13 not taken.
51965349 for (auto& script_object : script_objects | std::views::values)
2544 {
2545
3/4
✓ Branch 0 taken 49503683 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 168 times.
✓ Branch 3 taken 49503515 times.
49503683 if (script_object->own_clear(scriptType, UID))
2546 {
2547
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 ids_to_clear.push_back(script_object->id);
2548 168 script_object->owned_type = ScriptType::None;
2549 168 script_object->owned_i = 0;
2550 168 }
2551 }
2552
2553
6/8
✓ Branch 0 taken 2461666 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 965873 times.
✓ Branch 3 taken 1495793 times.
✓ Branch 4 taken 965873 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 577437 times.
✓ Branch 7 taken 388436 times.
2461666 if (ZScriptVersion::gc() && script_engine_data_exists(scriptType, UID))
2554 {
2555
1/2
✓ Branch 0 taken 577437 times.
✗ Branch 1 not taken.
577437 auto& data = get_script_engine_data(scriptType, UID);
2556
2/2
✓ Branch 0 taken 242 times.
✓ Branch 1 taken 577437 times.
577679 for (uint32_t offset : data.ref.stack_pos_is_object)
2557 {
2558 242 uint32_t id = data.stack[offset];
2559
1/2
✓ Branch 0 taken 242 times.
✗ Branch 1 not taken.
242 ids_to_clear.push_back(id);
2560 }
2561 577437 data.ref.stack_pos_is_object.clear();
2562 577437 }
2563
2564
3/4
✓ Branch 0 taken 2461666 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 965873 times.
✓ Branch 3 taken 1495793 times.
2461666 if (ZScriptVersion::gc())
2565 {
2566
2/2
✓ Branch 0 taken 261 times.
✓ Branch 1 taken 965873 times.
966134 for (auto id : ids_to_clear)
2567
1/2
✓ Branch 0 taken 261 times.
✗ Branch 1 not taken.
261 script_object_ref_dec(id);
2568 965873 }
2569 else
2570 {
2571
2/2
✓ Branch 0 taken 149 times.
✓ Branch 1 taken 1495793 times.
1495942 for (auto id : ids_to_clear)
2572
1/2
✓ Branch 0 taken 149 times.
✗ Branch 1 not taken.
149 delete_script_object(id);
2573 }
2574
2575
3/4
✓ Branch 0 taken 2461666 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 927948 times.
✓ Branch 3 taken 1533718 times.
2461666 if (!ZScriptVersion::gc_arrays())
2576 {
2577
2/2
✓ Branch 0 taken 6280575210 times.
✓ Branch 1 taken 1533718 times.
6282108928 for(int32_t i = 1; i < NUM_ZSCRIPT_ARRAYS; i++)
2578 {
2579
3/4
✓ Branch 0 taken 6280575210 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30496 times.
✓ Branch 3 taken 6280544714 times.
6280575210 if(arrayOwner[i].own_clear(scriptType,UID))
2580
1/2
✓ Branch 0 taken 30496 times.
✗ Branch 1 not taken.
30496 deallocateArray(i);
2581 6280575210 }
2582 1533718 }
2583 2461666 }
2584
2585 133254 void FFScript::deallocateAllScriptOwnedOfType(ScriptType scriptType)
2586 {
2587 133254 std::vector<uint32_t> ids_to_clear;
2588
8/14
✓ Branch 0 taken 133254 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 133254 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 133254 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 482709 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 349455 times.
✓ Branch 9 taken 133254 times.
✓ Branch 10 taken 349455 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 349455 times.
✗ Branch 13 not taken.
482709 for (auto& script_object : script_objects | std::views::values)
2589 {
2590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 349455 times.
349455 if (script_object->owned_type == scriptType)
2591 {
2592 ids_to_clear.push_back(script_object->id);
2593 script_object->owned_type = ScriptType::None;
2594 script_object->owned_i = 0;
2595 }
2596 }
2597
2598
3/4
✓ Branch 0 taken 133254 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64307 times.
✓ Branch 3 taken 68947 times.
133254 if (ZScriptVersion::gc())
2599 {
2600
2/2
✓ Branch 0 taken 134483077 times.
✓ Branch 1 taken 64307 times.
134547398 for (auto& [key, data] : scriptEngineDatas)
2601 {
2602
2/2
✓ Branch 0 taken 134483063 times.
✓ Branch 1 taken 14 times.
134483077 if (key.first != scriptType)
2603 134483063 continue;
2604
2605
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 for (uint32_t offset : data.ref.stack_pos_is_object)
2606 {
2607 uint32_t id = data.stack[offset];
2608 ids_to_clear.push_back(id);
2609 }
2610 14 data.ref.stack_pos_is_object.clear();
2611 }
2612
2613
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64307 times.
64307 for (auto id : ids_to_clear)
2614 script_object_ref_dec(id);
2615 64307 }
2616 else
2617 {
2618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68947 times.
68947 for (auto id : ids_to_clear)
2619 delete_script_object(id);
2620 }
2621
2622
3/4
✓ Branch 0 taken 133254 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 63906 times.
✓ Branch 3 taken 69348 times.
133254 if (!ZScriptVersion::gc_arrays())
2623 {
2624
2/2
✓ Branch 0 taken 283980060 times.
✓ Branch 1 taken 69348 times.
284049408 for(int32_t i = 1; i < NUM_ZSCRIPT_ARRAYS; i++)
2625 {
2626
1/2
✓ Branch 0 taken 283980060 times.
✗ Branch 1 not taken.
283980060 if(arrayOwner[i].owned_type == scriptType)
2627 deallocateArray(i);
2628 283980060 }
2629 69348 }
2630 133254 }
2631
2632 // Only called when resetting the engine. Don't keep anything.
2633 375 void FFScript::deallocateAllScriptOwned()
2634 {
2635 375 script_object_ids_by_type.clear();
2636 375 script_objects.clear();
2637 375 next_script_object_id_freelist.clear();
2638
2639
2/2
✓ Branch 0 taken 166 times.
✓ Branch 1 taken 209 times.
375 if (!ZScriptVersion::gc_arrays())
2640 {
2641
2/2
✓ Branch 0 taken 855855 times.
✓ Branch 1 taken 209 times.
856064 for(int32_t i = 1; i < NUM_ZSCRIPT_ARRAYS; i++)
2642 {
2643
2/2
✓ Branch 0 taken 855693 times.
✓ Branch 1 taken 162 times.
855855 if(localRAM[i].Valid())
2644 {
2645 // Unowned arrays are ALSO deallocated!
2646 162 arrayOwner[i].clear();
2647 162 localRAM[i].Clear();
2648 162 }
2649 855855 }
2650 209 }
2651 375 }
2652
2653 660 void FFScript::deallocateAllScriptOwnedCont()
2654 {
2655 660 std::vector<uint32_t> ids_to_clear;
2656
8/14
✓ Branch 0 taken 660 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 660 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 660 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3814 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3154 times.
✓ Branch 9 taken 660 times.
✓ Branch 10 taken 3154 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3154 times.
✗ Branch 13 not taken.
3814 for (auto& script_object : script_objects | std::views::values)
2657 {
2658
2/4
✓ Branch 0 taken 3154 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3154 times.
3154 if (script_object->own_clear_cont())
2659 {
2660 ids_to_clear.push_back(script_object->id);
2661 script_object->owned_type = ScriptType::None;
2662 script_object->owned_i = 0;
2663 }
2664 }
2665
2666
3/4
✓ Branch 0 taken 660 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 269 times.
✓ Branch 3 taken 391 times.
660 if (ZScriptVersion::gc())
2667 {
2668
2/2
✓ Branch 0 taken 345281 times.
✓ Branch 1 taken 269 times.
690831 for (auto& [key, data] : scriptEngineDatas)
2669 {
2670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 345281 times.
345281 for (uint32_t offset : data.ref.stack_pos_is_object)
2671 {
2672 uint32_t id = data.stack[offset];
2673 ids_to_clear.push_back(id);
2674 }
2675 345281 data.ref.stack_pos_is_object.clear();
2676 }
2677
2678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 269 times.
269 for (auto id : ids_to_clear)
2679 script_object_ref_dec(id);
2680 269 }
2681 else
2682 {
2683
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 391 times.
391 for (auto id : ids_to_clear)
2684 delete_script_object(id);
2685 }
2686
2687
3/4
✓ Branch 0 taken 660 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 269 times.
✓ Branch 3 taken 391 times.
660 if (!ZScriptVersion::gc_arrays())
2688 {
2689 //No QR check here- always deallocate on quest exit.
2690
2/2
✓ Branch 0 taken 1601145 times.
✓ Branch 1 taken 391 times.
1601536 for(int32_t i = 1; i < NUM_ZSCRIPT_ARRAYS; i++)
2691 {
2692
3/4
✓ Branch 0 taken 1601145 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3165 times.
✓ Branch 3 taken 1597980 times.
1601145 if(localRAM[i].Valid())
2693 {
2694
2/4
✓ Branch 0 taken 3165 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3165 times.
✗ Branch 3 not taken.
3165 if(arrayOwner[i].own_clear_cont())
2695
1/2
✓ Branch 0 taken 3165 times.
✗ Branch 1 not taken.
3165 deallocateArray(i);
2696 3165 }
2697 1601145 }
2698 391 }
2699 660 }
2700
2701 9933550 weapon *checkLWpn(int32_t uid)
2702 {
2703 9933550 return ResolveSprite<weapon>(uid, "lweapon");
2704 }
2705
2706 19351233 weapon *checkEWpn(int32_t uid)
2707 {
2708 19351233 return ResolveSprite<weapon>(uid, "eweapon");
2709 }
2710
2711 29434315 weapon *checkWpn(int32_t uid)
2712 {
2713 29434315 return ResolveSprite<weapon>(uid, "weapon");
2714 }
2715
2716 566 user_file *checkFile(int32_t ref, bool req_file = false, bool skipError = false)
2717 {
2718 566 user_file* file = user_files.check(ref, skipError);
2719
5/6
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 560 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 560 times.
✗ Branch 5 not taken.
566 if (file && req_file && !file->file)
2720 {
2721 if (skipError) return NULL;
2722
2723 scripting_log_error_with_context("Script attempted to reference an invalid file!");
2724 Z_scripterrlog("File with UID = %ld does not have an open file connection!\n", ref);
2725 Z_scripterrlog("Use '->Open()' or '->Create()' to hook to a system file.\n");
2726 return NULL;
2727 }
2728 566 return file;
2729 566 }
2730
2731 8474683 user_genscript *checkGenericScr(int32_t ref)
2732 {
2733
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8474683 times.
8474683 if (BC::checkBounds(ref, 1, NUMSCRIPTSGENERIC-1) != SH::_NoError)
2734 return NULL;
2735
2736 8474683 return &user_genscript::get(ref);
2737 8474683 }
2738 extern portal mirror_portal;
2739 portal *checkPortal(int32_t ref, bool skiperr = false)
2740 {
2741 if(ref == -1)
2742 return &mirror_portal;
2743
2744 portal* p = (portal*)portals.getByUID(ref);
2745 if(!p)
2746 {
2747 if(!skiperr)
2748 scripting_log_error_with_context("Invalid portal pointer: {}", ref);
2749 return nullptr;
2750 }
2751 return p;
2752 }
2753
2754 savedportal *checkSavedPortal(int32_t ref, bool skiperr = false)
2755 {
2756 savedportal* sp = game->getSavedPortal(ref);
2757 if(!sp)
2758 {
2759 if(!skiperr)
2760 scripting_log_error_with_context("Invalid savedportal pointer: {}", ref);
2761 return nullptr;
2762 }
2763 return sp;
2764 }
2765 int32_t getPortalFromSaved(savedportal* p)
2766 {
2767 if(p == &(game->saved_mirror_portal))
2768 return -1;
2769 portal* prtl = nullptr;
2770 portals.forEach([&](sprite& spr)
2771 {
2772 portal* tmp = (portal*)&spr;
2773 if(p->getUID() == tmp->saved_data)
2774 {
2775 prtl = tmp;
2776 return true;
2777 }
2778 return false;
2779 });
2780 return prtl ? prtl->getUID() : 0;
2781 }
2782
2783 static user_dir *checkDir(uint32_t id, bool skipError = false)
2784 {
2785 return user_dirs.check(id, skipError);
2786 }
2787
2788 static user_stack *checkStack(uint32_t id, bool skipError = false)
2789 {
2790 return user_stacks.check(id, skipError);
2791 }
2792
2793 449481 static user_rng *checkRNG(uint32_t id, bool skipError = false)
2794 {
2795 // A null RNG pointer is special-case, access engine rng.
2796
2/2
✓ Branch 0 taken 447958 times.
✓ Branch 1 taken 1523 times.
449481 if (id == 0) return &nulrng;
2797 1523 return user_rngs.check(id, skipError);
2798 449481 }
2799
2800 17949 user_paldata* checkPalData(int32_t ref, bool skipError)
2801 {
2802 17949 return user_paldatas.check(ref, skipError);
2803 }
2804
2805 42504 newcombo* checkCombo(int32_t ref, bool skipError)
2806 {
2807
2/4
✓ Branch 0 taken 42504 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 42504 times.
42504 if (ref < 0 || ref > (MAXCOMBOS-1) )
2808 {
2809 scripting_log_error_with_context("Invalid combodata ID: {}", ref);
2810 return nullptr;
2811 }
2812
2813 42504 return &combobuf[ref];
2814 42504 }
2815
2816 newcombo* checkComboFromTriggerRef(dword ref)
2817 {
2818 ref = get_combo_from_trigger_ref(ref);
2819 return checkCombo(ref);
2820 }
2821
2822 44562 dmap* checkDmap(int32_t ref)
2823 {
2824
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44562 times.
44562 if (BC::checkDMapID(ref) != SH::_NoError)
2825 return nullptr;
2826
2827 44562 return &DMaps[ref];
2828 44562 }
2829
2830 23474048 ffcdata* checkFFC(int32_t ref)
2831 {
2832 23474048 return ResolveFFC(ref);
2833 }
2834
2835 45830930 enemy* checkNPC(int32_t ref)
2836 {
2837 45830930 return ResolveNpc(ref);
2838 }
2839
2840 guydata* checkNPCData(int32_t ref)
2841 {
2842 if (ref >= 0 && ref < MAXNPCS)
2843 return &guysbuf[ref];
2844
2845 scripting_log_error_with_context("Invalid {} using UID = {}", "npcdata", ref);
2846 return nullptr;
2847 }
2848
2849 2239361 item* checkItem(int32_t ref)
2850 {
2851 2239361 return ResolveItemSprite(ref);
2852 }
2853
2854 167 itemdata* checkItemData(int32_t ref)
2855 {
2856
2/4
✓ Branch 0 taken 167 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 167 times.
✗ Branch 3 not taken.
167 if (ref >= 0 && ref < MAXITEMS)
2857 167 return &itemsbuf[ref];
2858
2859 scripting_log_error_with_context("Invalid {} using UID = {}", "itemdata", ref);
2860 return nullptr;
2861 167 }
2862
2863 88347449 mapdata* checkMapData(int32_t ref)
2864 {
2865 static mapdata last_result;
2866
2867 88347449 last_result = decode_mapdata_ref(ref);
2868
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 88347449 times.
88347449 if (!last_result.scr)
2869 {
2870 scripting_log_error_with_context("Invalid {} using UID = {}", "mapdata", ref);
2871 return nullptr;
2872 }
2873
2874 88347449 return &last_result;
2875 88347449 }
2876
2877 45472 mapscr* checkMapDataScr(int32_t ref)
2878 {
2879 45472 return decode_mapdata_ref(ref).scr;
2880 }
2881
2882 24924060 screendata* checkScreen(int32_t ref)
2883 {
2884 24924060 return (screendata*)get_scr_maybe(cur_map, ref);
2885 }
2886
2887 bottletype* checkBottleData(int32_t ref, bool skipError)
2888 {
2889 if(ref > 0 && ref <= 64)
2890 {
2891 return &QMisc.bottle_types[ref-1];
2892 }
2893 if(skipError) return NULL;
2894
2895 scripting_log_error_with_context("Invalid {} using UID = {}", "bottledata", ref);
2896 return NULL;
2897 }
2898
2899 bottleshoptype *checkBottleShopData(int32_t ref, bool skipError)
2900 {
2901 if(ref > 0 && ref <= 256)
2902 {
2903 return &QMisc.bottle_shop_types[ref-1];
2904 }
2905 if(skipError) return NULL;
2906
2907 scripting_log_error_with_context("Invalid {} using UID = {}", "bottleshopdata", ref);
2908 return NULL;
2909 }
2910
2911 item_drop_object *checkDropSetData(int32_t ref)
2912 {
2913 if(ref > 0 && ref < MAXITEMDROPSETS)
2914 return &item_drop_sets[ref];
2915
2916 scripting_log_error_with_context("Invalid {} using UID = {}", "dropsetdata", ref);
2917 return NULL;
2918 }
2919
2920 wpndata *checkSpriteData(int32_t ref)
2921 {
2922 if(ref > 0 && ref < MAXWPNS)
2923 return &wpnsbuf[ref];
2924
2925 scripting_log_error_with_context("Invalid {} using UID = {}", "spritedata", ref);
2926 return NULL;
2927 }
2928
2929 MsgStr *checkMessageData(int32_t ref)
2930 {
2931 if(ref > 0 && ref < msg_strings_size)
2932 return &MsgStrings[ref];
2933
2934 scripting_log_error_with_context("Invalid {} using UID = {}", "messagedata", ref);
2935 return NULL;
2936 }
2937
2938 combo_trigger* checkComboTrigger(dword ref)
2939 {
2940 return get_combo_trigger(ref);
2941 }
2942
2943 53724680 user_bitmap *checkBitmap(int32_t ref, bool req_valid = false, bool skipError = false)
2944 {
2945
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53724680 times.
53724680 switch (ref - 10)
2946 {
2947 case rtSCREEN:
2948 case rtBMP0:
2949 case rtBMP1:
2950 case rtBMP2:
2951 case rtBMP3:
2952 case rtBMP4:
2953 case rtBMP5:
2954 case rtBMP6:
2955 zprint2("Internal error: 'checkBitmap()' recieved ref pointing to system bitmap!\n");
2956 zprint2("Please report this as a bug!\n");
2957
2958 if(skipError) return NULL;
2959
2960 scripting_log_error_with_context("Tried to reference a non-existent bitmap with UID = {}", ref);
2961 return NULL;
2962
2963 default:
2964 {
2965 53724680 user_bitmap* b = user_bitmaps.check(ref, skipError);
2966
4/6
✓ Branch 0 taken 53694494 times.
✓ Branch 1 taken 30186 times.
✓ Branch 2 taken 53694494 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 53694494 times.
✗ Branch 5 not taken.
53724680 if (req_valid && (!b || !b->u_bmp))
2967 {
2968 if (skipError) return NULL;
2969
2970 scripting_log_error_with_context("Tried to reference an invalid user bitmap with UID = {}.", ref);
2971 Z_scripterrlog("Did you forget to create the bitmap with `new bitmap()` or `->Create()`?.\n");
2972 return NULL;
2973 }
2974 53724680 return b;
2975 }
2976 }
2977 53724680 }
2978
2979 extern const std::string subscr_names[sstMAX];
2980 159701 ZCSubscreen *checkSubData(int32_t ref, int req_ty)
2981 {
2982 319402 auto [ptr,ty] = load_subdata(ref);
2983
1/2
✓ Branch 0 taken 159701 times.
✗ Branch 1 not taken.
159701 if(ptr)
2984 {
2985
4/6
✓ Branch 0 taken 5097 times.
✓ Branch 1 taken 154604 times.
✓ Branch 2 taken 5097 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5097 times.
✗ Branch 5 not taken.
159701 if(req_ty < 0 || req_ty == ty)
2986 159701 return ptr;
2987 else
2988 {
2989 scripting_log_error_with_context("Wrong type of SubscreenData accessed! Expecting type '{}', but found '{}'",
2990 subscr_names[req_ty], subscr_names[ty]);
2991 }
2992 }
2993 else scripting_log_error_with_context("Script attempted to reference a nonexistent SubscreenData!");
2994
2995 scripting_log_error_with_context("You were trying to reference an invalid SubscreenData with UID = {}", ref);
2996 return NULL;
2997 159701 }
2998
2999 56028 SubscrPage *checkSubPage(int32_t ref, int req_ty)
3000 {
3001 112056 auto [ptr,ty] = load_subpage(ref);
3002
1/2
✓ Branch 0 taken 56028 times.
✗ Branch 1 not taken.
56028 if(ptr)
3003 {
3004
4/6
✓ Branch 0 taken 14870 times.
✓ Branch 1 taken 41158 times.
✓ Branch 2 taken 14870 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14870 times.
✗ Branch 5 not taken.
56028 if(req_ty < 0 || req_ty == ty)
3005 56028 return ptr;
3006 else
3007 {
3008 scripting_log_error_with_context("Wrong type of Subscreen accessed! Expecting type '{}', but found '{}'",
3009 subscr_names[req_ty], subscr_names[ty]);
3010 }
3011 }
3012 else scripting_log_error_with_context("Script attempted to reference a nonexistent SubscreenPage!");
3013
3014 scripting_log_error_with_context("You were trying to reference an invalid SubscreenPage with UID = {}", ref);
3015 return NULL;
3016 56028 }
3017
3018 103742 SubscrWidget *checkSubWidg(int32_t ref, int req_widg_ty, int req_sub_ty)
3019 {
3020 207484 auto [ptr,ty] = load_subwidg(ref);
3021
1/2
✓ Branch 0 taken 103742 times.
✗ Branch 1 not taken.
103742 if(ptr)
3022 {
3023
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 103742 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
103742 if(req_sub_ty < 0 || req_sub_ty == ty)
3024 {
3025
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 103742 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
103742 if(req_widg_ty < 0 || req_widg_ty == ptr->getType())
3026 103742 return ptr;
3027 else
3028 {
3029 auto listdata = GUI::ZCListData::subscr_widgets();
3030 scripting_log_error_with_context("Wrong type of SubscreenWidget accessed! Expecting type '{}', but found '{}'",
3031 listdata.findText(req_widg_ty), listdata.findText(ptr->getType()));
3032 }
3033 }
3034 else
3035 {
3036 scripting_log_error_with_context("Wrong type of Subscreen accessed! Expecting subscreen type '{}', but found '{}'",
3037 subscr_names[req_sub_ty], subscr_names[ty]);
3038 }
3039 }
3040 else scripting_log_error_with_context("Script attempted to reference a nonexistent SubscreenWidget!");
3041
3042 scripting_log_error_with_context("You were trying to reference an invalid SubscreenWidget with UID = {}", ref);
3043 return NULL;
3044 103742 }
3045
3046 static void bad_subwidg_type(bool func, byte type)
3047 {
3048 auto tyname = type < widgMAX ? subwidg_internal_names[type].c_str() : "";
3049 scripting_log_error_with_context("Widget type {} '{}' does not have this {}!",
3050 type, tyname, func ? "function" : "value");
3051 }
3052
3053 // TODO: Remove this.
3054 sprite *s;
3055
3056 3 int32_t item_flag(item_flags flag)
3057 {
3058
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(unsigned(ri->idata) >= MAXITEMS)
3059 {
3060 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3061 return 0;
3062 }
3063 3 return (itemsbuf[ri->idata].flags & flag) ? 10000 : 0;
3064 3 }
3065 void item_flag(item_flags flag, bool val)
3066 {
3067 if(unsigned(ri->idata) >= MAXITEMS)
3068 {
3069 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3070 return;
3071 }
3072 SETFLAG(itemsbuf[ri->idata].flags, flag, val);
3073 }
3074
3075 bool scripting_use_8bit_colors;
3076 int scripting_max_color_val;
3077
3078 440756 static int scripting_read_pal_color(int c)
3079 {
3080
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 440756 times.
440756 return scripting_use_8bit_colors ? c : c / 4;
3081 }
3082
3083 139440 static int scripting_write_pal_color(int c)
3084 {
3085
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 139440 times.
139440 return scripting_use_8bit_colors ? c : _rgb_scale_6[c];
3086 }
3087
3088 7675 void apply_qr_rule(int qr_id)
3089 {
3090 7675 bool value = get_qr(qr_id);
3091
6/6
✓ Branch 0 taken 2283 times.
✓ Branch 1 taken 1077 times.
✓ Branch 2 taken 1077 times.
✓ Branch 3 taken 1077 times.
✓ Branch 4 taken 1077 times.
✓ Branch 5 taken 1084 times.
7675 switch (qr_id)
3092 {
3093 case qr_LTTPWALK:
3094 1077 Hero.setDiagMove(value?1:0);
3095 1077 break;
3096 case qr_LTTPCOLLISION:
3097 1077 Hero.setBigHitbox(value?1:0);
3098 1077 break;
3099 case qr_ZS_NO_NEG_ARRAY:
3100 1077 can_neg_array = !value;
3101 1077 break;
3102 case qr_SCRIPTS_6_BIT_COLOR:
3103 {
3104
1/2
✓ Branch 0 taken 1077 times.
✗ Branch 1 not taken.
1077 if (value)
3105 {
3106 1077 scripting_use_8bit_colors = false;
3107 1077 scripting_max_color_val = 63;
3108 1077 }
3109 else
3110 {
3111 scripting_use_8bit_colors = true;
3112 scripting_max_color_val = 255;
3113 }
3114 1077 break;
3115 }
3116 case qr_HIDE_BOTTOM_8_PIXELS:
3117 {
3118 1084 updateShowBottomPixels();
3119 1084 break;
3120 }
3121 }
3122 7675 }
3123
3124 1077 static void apply_qr_rules()
3125 {
3126 1077 apply_qr_rule(qr_HIDE_BOTTOM_8_PIXELS);
3127 1077 apply_qr_rule(qr_LTTPCOLLISION);
3128 1077 apply_qr_rule(qr_LTTPWALK);
3129 1077 apply_qr_rule(qr_SCRIPTS_6_BIT_COLOR);
3130 1077 apply_qr_rule(qr_ZS_NO_NEG_ARRAY);
3131 1077 }
3132
3133 //Forward decl
3134 int32_t do_msgheight(int32_t msg);
3135 int32_t do_msgwidth(int32_t msg);
3136 //
3137
3138 template <typename T, size_t N>
3139 static int read_array(const T(&arr)[N], int index)
3140 {
3141 if (BC::checkIndex(index, 0, N - 1) != SH::_NoError)
3142 return 0;
3143
3144 return arr[index];
3145 }
3146
3147 template <typename T, size_t N>
3148 static bool write_array(T(&arr)[N], int index, T value)
3149 {
3150 if (BC::checkIndex(index, 0, N - 1) != SH::_NoError)
3151 return false;
3152
3153 arr[index] = value;
3154 return true;
3155 }
3156
3157 227698034 static int get_ref(int arg)
3158 {
3159
15/26
✗ Branch 0 not taken.
✓ Branch 1 taken 2206362 times.
✓ Branch 2 taken 88302904 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2475 times.
✓ Branch 5 taken 102 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 42504 times.
✓ Branch 10 taken 44517 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 27227949 times.
✓ Branch 13 taken 23474048 times.
✓ Branch 14 taken 8469043 times.
✓ Branch 15 taken 169465 times.
✓ Branch 16 taken 167 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 45830930 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 27524918 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 4352670 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 49980 times.
✗ Branch 25 not taken.
227698034 switch (arg)
3160 {
3161 case REFBITMAP: return ri->bitmapref;
3162 case REFBOTTLESHOP: return ri->bottleshopref;
3163 case REFBOTTLETYPE: return ri->bottletyperef;
3164 42504 case REFCOMBODATA: return ri->combosref;
3165 case REFCOMBOTRIGGER: return ri->combotrigref;
3166 44517 case REFDMAPDATA: return ri->dmapsref;
3167 case REFDROPS: return ri->dropsetref;
3168 27227949 case REFEWPN: return ri->ewpn;
3169 23474048 case REFFFC: return ri->ffcref;
3170 8469043 case REFGENERICDATA: return ri->genericdataref;
3171 169465 case REFITEM: return ri->itemref;
3172 167 case REFITEMCLASS: return ri->idata;
3173 2206362 case REFLWPN: return ri->lwpn;
3174 88302904 case REFMAPDATA: return ri->mapsref;
3175 case REFMSGDATA: return ri->zmsgref;
3176 45830930 case REFNPC: return ri->guyref;
3177 case REFNPCCLASS: return ri->npcdataref;
3178 case REFPALDATA: return ri->paldataref;
3179 27524918 case REFSCREENDATA: return ri->screenref;
3180 case REFSHOPDATA: return ri->shopsref;
3181 4352670 case REFSPRITE: return ri->spriteref;
3182 case REFSPRITEDATA: return ri->spritedataref;
3183 49980 case REFSUBSCREEN: return ri->subdataref;
3184 2475 case REFSUBSCREENPAGE: return ri->subpageref;
3185 102 case REFSUBSCREENWIDG: return ri->subwidgref;
3186
3187 default: NOTREACHED();
3188 }
3189 227698034 }
3190
3191 int32_t earlyretval = -1;
3192 3968762533 int32_t get_register(int32_t arg)
3193 {
3194
3/4
✓ Branch 0 taken 3968762533 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2856454483 times.
✓ Branch 3 taken 1112308050 times.
3968762533 if (arg >= D(0) && arg <= D(7))
3195 1112308050 return ri->d[arg - D(0)];
3196
3197
4/4
✓ Branch 0 taken 2378954702 times.
✓ Branch 1 taken 477499781 times.
✓ Branch 2 taken 2368722769 times.
✓ Branch 3 taken 10231933 times.
2856454483 if (arg >= GD(0) && arg <= GD(MAX_SCRIPT_REGISTERS))
3198 10231933 return game->global_d[arg - GD(0)];
3199
3200 2846222550 int32_t ret = 0;
3201
3202 #define GET_SPRITEDATA_VAR_INT(member) \
3203 { \
3204 if(unsigned(ri->spritedataref) > (MAXWPNS-1) ) \
3205 { \
3206 ret = -10000; \
3207 scripting_log_error_with_context("Invalid Sprite ID: {}", ri->spritedataref*10000); \
3208 } \
3209 else \
3210 ret = (wpnsbuf[ri->spritedataref].member * 10000); \
3211 }
3212
3213 2846222550 current_zasm_register = arg;
3214
3215 // Do not ever use `return` in these cases!
3216
282/1045
✓ Branch 0 taken 944827 times.
✓ Branch 1 taken 652486 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 718383 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 1125663332 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 632522608 times.
✓ Branch 16 taken 3175230 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 623627 times.
✓ Branch 19 taken 13052062 times.
✓ Branch 20 taken 531424988 times.
✓ Branch 21 taken 2312685 times.
✓ Branch 22 taken 10 times.
✓ Branch 23 taken 24185371 times.
✓ Branch 24 taken 23746251 times.
✓ Branch 25 taken 5823966 times.
✓ Branch 26 taken 163102 times.
✓ Branch 27 taken 375 times.
✓ Branch 28 taken 51 times.
✓ Branch 29 taken 51 times.
✓ Branch 30 taken 204076 times.
✓ Branch 31 taken 199035 times.
✓ Branch 32 taken 5283857 times.
✓ Branch 33 taken 5194596 times.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✓ Branch 36 taken 41781171 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 42668369 times.
✓ Branch 39 taken 4020681 times.
✓ Branch 40 taken 719568 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 9094315 times.
✓ Branch 43 taken 441276 times.
✓ Branch 44 taken 24133498 times.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✓ Branch 47 taken 2790135 times.
✓ Branch 48 taken 1061314 times.
✓ Branch 49 taken 78367192 times.
✗ Branch 50 not taken.
✓ Branch 51 taken 204 times.
✓ Branch 52 taken 5424 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 1249005 times.
✓ Branch 55 taken 573955 times.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✓ Branch 59 taken 959935 times.
✓ Branch 60 taken 1095514 times.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✓ Branch 64 taken 656387 times.
✓ Branch 65 taken 571655 times.
✓ Branch 66 taken 113145 times.
✓ Branch 67 taken 115547 times.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✓ Branch 72 taken 489104 times.
✓ Branch 73 taken 489104 times.
✓ Branch 74 taken 288295 times.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✓ Branch 77 taken 4101 times.
✗ Branch 78 not taken.
✓ Branch 79 taken 57322 times.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✓ Branch 85 taken 180367 times.
✓ Branch 86 taken 440770 times.
✓ Branch 87 taken 2 times.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✓ Branch 90 taken 428588 times.
✓ Branch 91 taken 432590 times.
✓ Branch 92 taken 337110 times.
✓ Branch 93 taken 273630 times.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
✓ Branch 96 taken 271788 times.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✓ Branch 101 taken 832354 times.
✓ Branch 102 taken 18 times.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✓ Branch 105 taken 4357 times.
✗ Branch 106 not taken.
✓ Branch 107 taken 1012 times.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
✗ Branch 112 not taken.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✗ Branch 116 not taken.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✗ Branch 119 not taken.
✗ Branch 120 not taken.
✗ Branch 121 not taken.
✗ Branch 122 not taken.
✗ Branch 123 not taken.
✗ Branch 124 not taken.
✓ Branch 125 taken 136185 times.
✗ Branch 126 not taken.
✗ Branch 127 not taken.
✗ Branch 128 not taken.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✗ Branch 132 not taken.
✗ Branch 133 not taken.
✓ Branch 134 taken 92967 times.
✓ Branch 135 taken 4123 times.
✓ Branch 136 taken 4321356 times.
✓ Branch 137 taken 3824036 times.
✓ Branch 138 taken 4211785 times.
✓ Branch 139 taken 4388042 times.
✓ Branch 140 taken 6701954 times.
✓ Branch 141 taken 5699839 times.
✓ Branch 142 taken 3218568 times.
✓ Branch 143 taken 3214309 times.
✓ Branch 144 taken 120159 times.
✓ Branch 145 taken 120450 times.
✓ Branch 146 taken 23391 times.
✓ Branch 147 taken 23391 times.
✗ Branch 148 not taken.
✗ Branch 149 not taken.
✗ Branch 150 not taken.
✗ Branch 151 not taken.
✓ Branch 152 taken 791031 times.
✓ Branch 153 taken 791031 times.
✗ Branch 154 not taken.
✓ Branch 155 taken 1073638 times.
✓ Branch 156 taken 818518 times.
✓ Branch 157 taken 335732 times.
✓ Branch 158 taken 1118025 times.
✓ Branch 159 taken 1056398 times.
✓ Branch 160 taken 963357 times.
✓ Branch 161 taken 870340 times.
✓ Branch 162 taken 2442823 times.
✓ Branch 163 taken 1811399 times.
✓ Branch 164 taken 2061226 times.
✓ Branch 165 taken 1845780 times.
✓ Branch 166 taken 1237553 times.
✓ Branch 167 taken 1081361 times.
✓ Branch 168 taken 558264 times.
✓ Branch 169 taken 669416 times.
✗ Branch 170 not taken.
✗ Branch 171 not taken.
✗ Branch 172 not taken.
✗ Branch 173 not taken.
✗ Branch 174 not taken.
✗ Branch 175 not taken.
✗ Branch 176 not taken.
✗ Branch 177 not taken.
✗ Branch 178 not taken.
✗ Branch 179 not taken.
✗ Branch 180 not taken.
✗ Branch 181 not taken.
✗ Branch 182 not taken.
✗ Branch 183 not taken.
✗ Branch 184 not taken.
✗ Branch 185 not taken.
✗ Branch 186 not taken.
✗ Branch 187 not taken.
✗ Branch 188 not taken.
✗ Branch 189 not taken.
✗ Branch 190 not taken.
✗ Branch 191 not taken.
✗ Branch 192 not taken.
✗ Branch 193 not taken.
✗ Branch 194 not taken.
✗ Branch 195 not taken.
✗ Branch 196 not taken.
✗ Branch 197 not taken.
✗ Branch 198 not taken.
✗ Branch 199 not taken.
✗ Branch 200 not taken.
✓ Branch 201 taken 53 times.
✗ Branch 202 not taken.
✗ Branch 203 not taken.
✗ Branch 204 not taken.
✗ Branch 205 not taken.
✗ Branch 206 not taken.
✓ Branch 207 taken 5960535 times.
✓ Branch 208 taken 16858 times.
✓ Branch 209 taken 3 times.
✗ Branch 210 not taken.
✗ Branch 211 not taken.
✗ Branch 212 not taken.
✗ Branch 213 not taken.
✗ Branch 214 not taken.
✗ Branch 215 not taken.
✗ Branch 216 not taken.
✗ Branch 217 not taken.
✗ Branch 218 not taken.
✗ Branch 219 not taken.
✗ Branch 220 not taken.
✗ Branch 221 not taken.
✗ Branch 222 not taken.
✓ Branch 223 taken 1994 times.
✓ Branch 224 taken 1914 times.
✗ Branch 225 not taken.
✗ Branch 226 not taken.
✗ Branch 227 not taken.
✗ Branch 228 not taken.
✗ Branch 229 not taken.
✗ Branch 230 not taken.
✗ Branch 231 not taken.
✗ Branch 232 not taken.
✗ Branch 233 not taken.
✗ Branch 234 not taken.
✗ Branch 235 not taken.
✗ Branch 236 not taken.
✗ Branch 237 not taken.
✓ Branch 238 taken 55670 times.
✗ Branch 239 not taken.
✓ Branch 240 taken 55645 times.
✗ Branch 241 not taken.
✓ Branch 242 taken 63041 times.
✓ Branch 243 taken 142873 times.
✓ Branch 244 taken 74538 times.
✗ Branch 245 not taken.
✗ Branch 246 not taken.
✗ Branch 247 not taken.
✗ Branch 248 not taken.
✗ Branch 249 not taken.
✗ Branch 250 not taken.
✗ Branch 251 not taken.
✗ Branch 252 not taken.
✗ Branch 253 not taken.
✗ Branch 254 not taken.
✗ Branch 255 not taken.
✓ Branch 256 taken 954757 times.
✗ Branch 257 not taken.
✓ Branch 258 taken 950150 times.
✓ Branch 259 taken 109736 times.
✓ Branch 260 taken 6 times.
✗ Branch 261 not taken.
✓ Branch 262 taken 80933 times.
✗ Branch 263 not taken.
✓ Branch 264 taken 5388 times.
✓ Branch 265 taken 416 times.
✗ Branch 266 not taken.
✓ Branch 267 taken 246 times.
✗ Branch 268 not taken.
✓ Branch 269 taken 6 times.
✗ Branch 270 not taken.
✗ Branch 271 not taken.
✓ Branch 272 taken 6 times.
✓ Branch 273 taken 103896 times.
✓ Branch 274 taken 7611 times.
✓ Branch 275 taken 4109108 times.
✓ Branch 276 taken 53697 times.
✓ Branch 277 taken 586 times.
✓ Branch 278 taken 53381 times.
✓ Branch 279 taken 220 times.
✓ Branch 280 taken 4362 times.
✓ Branch 281 taken 4362 times.
✓ Branch 282 taken 6 times.
✗ Branch 283 not taken.
✓ Branch 284 taken 1950927 times.
✓ Branch 285 taken 6 times.
✓ Branch 286 taken 835937 times.
✓ Branch 287 taken 23909 times.
✓ Branch 288 taken 299718 times.
✓ Branch 289 taken 296970 times.
✓ Branch 290 taken 10231 times.
✓ Branch 291 taken 11477 times.
✗ Branch 292 not taken.
✗ Branch 293 not taken.
✗ Branch 294 not taken.
✓ Branch 295 taken 6 times.
✓ Branch 296 taken 283042 times.
✓ Branch 297 taken 284996 times.
✓ Branch 298 taken 36540 times.
✓ Branch 299 taken 32019 times.
✓ Branch 300 taken 32019 times.
✓ Branch 301 taken 5455 times.
✗ Branch 302 not taken.
✗ Branch 303 not taken.
✗ Branch 304 not taken.
✓ Branch 305 taken 3 times.
✓ Branch 306 taken 60075 times.
✗ Branch 307 not taken.
✗ Branch 308 not taken.
✗ Branch 309 not taken.
✓ Branch 310 taken 1552 times.
✗ Branch 311 not taken.
✗ Branch 312 not taken.
✗ Branch 313 not taken.
✗ Branch 314 not taken.
✓ Branch 315 taken 48553 times.
✗ Branch 316 not taken.
✗ Branch 317 not taken.
✗ Branch 318 not taken.
✗ Branch 319 not taken.
✗ Branch 320 not taken.
✗ Branch 321 not taken.
✗ Branch 322 not taken.
✗ Branch 323 not taken.
✗ Branch 324 not taken.
✗ Branch 325 not taken.
✗ Branch 326 not taken.
✗ Branch 327 not taken.
✗ Branch 328 not taken.
✓ Branch 329 taken 4354386 times.
✗ Branch 330 not taken.
✓ Branch 331 taken 4354484 times.
✓ Branch 332 taken 552907 times.
✗ Branch 333 not taken.
✗ Branch 334 not taken.
✓ Branch 335 taken 61563 times.
✓ Branch 336 taken 2845 times.
✗ Branch 337 not taken.
✓ Branch 338 taken 610345 times.
✗ Branch 339 not taken.
✗ Branch 340 not taken.
✗ Branch 341 not taken.
✓ Branch 342 taken 136793 times.
✗ Branch 343 not taken.
✗ Branch 344 not taken.
✓ Branch 345 taken 46359 times.
✓ Branch 346 taken 90304 times.
✓ Branch 347 taken 6052 times.
✓ Branch 348 taken 2800078 times.
✓ Branch 349 taken 205013 times.
✗ Branch 350 not taken.
✗ Branch 351 not taken.
✓ Branch 352 taken 65315 times.
✗ Branch 353 not taken.
✓ Branch 354 taken 96 times.
✗ Branch 355 not taken.
✓ Branch 356 taken 96 times.
✗ Branch 357 not taken.
✓ Branch 358 taken 12006 times.
✓ Branch 359 taken 218 times.
✓ Branch 360 taken 6012394 times.
✗ Branch 361 not taken.
✓ Branch 362 taken 10477 times.
✗ Branch 363 not taken.
✓ Branch 364 taken 157773 times.
✓ Branch 365 taken 157773 times.
✓ Branch 366 taken 48464 times.
✓ Branch 367 taken 60558 times.
✗ Branch 368 not taken.
✗ Branch 369 not taken.
✗ Branch 370 not taken.
✓ Branch 371 taken 1880 times.
✓ Branch 372 taken 149564 times.
✓ Branch 373 taken 149564 times.
✓ Branch 374 taken 81355 times.
✓ Branch 375 taken 125257 times.
✓ Branch 376 taken 125257 times.
✓ Branch 377 taken 10565 times.
✗ Branch 378 not taken.
✗ Branch 379 not taken.
✗ Branch 380 not taken.
✗ Branch 381 not taken.
✓ Branch 382 taken 43 times.
✗ Branch 383 not taken.
✗ Branch 384 not taken.
✗ Branch 385 not taken.
✗ Branch 386 not taken.
✗ Branch 387 not taken.
✓ Branch 388 taken 30735 times.
✗ Branch 389 not taken.
✗ Branch 390 not taken.
✗ Branch 391 not taken.
✗ Branch 392 not taken.
✗ Branch 393 not taken.
✗ Branch 394 not taken.
✗ Branch 395 not taken.
✗ Branch 396 not taken.
✗ Branch 397 not taken.
✗ Branch 398 not taken.
✗ Branch 399 not taken.
✗ Branch 400 not taken.
✗ Branch 401 not taken.
✓ Branch 402 taken 792465 times.
✗ Branch 403 not taken.
✗ Branch 404 not taken.
✗ Branch 405 not taken.
✗ Branch 406 not taken.
✓ Branch 407 taken 225 times.
✓ Branch 408 taken 63717 times.
✓ Branch 409 taken 11271182 times.
✓ Branch 410 taken 96 times.
✗ Branch 411 not taken.
✓ Branch 412 taken 58184223 times.
✓ Branch 413 taken 15080301 times.
✗ Branch 414 not taken.
✗ Branch 415 not taken.
✗ Branch 416 not taken.
✓ Branch 417 taken 47264 times.
✓ Branch 418 taken 39568 times.
✓ Branch 419 taken 64 times.
✓ Branch 420 taken 20 times.
✓ Branch 421 taken 32 times.
✓ Branch 422 taken 982758 times.
✗ Branch 423 not taken.
✗ Branch 424 not taken.
✗ Branch 425 not taken.
✓ Branch 426 taken 24940 times.
✓ Branch 427 taken 21112 times.
✓ Branch 428 taken 8014 times.
✓ Branch 429 taken 11842 times.
✗ Branch 430 not taken.
✗ Branch 431 not taken.
✗ Branch 432 not taken.
✗ Branch 433 not taken.
✗ Branch 434 not taken.
✗ Branch 435 not taken.
✗ Branch 436 not taken.
✗ Branch 437 not taken.
✗ Branch 438 not taken.
✗ Branch 439 not taken.
✗ Branch 440 not taken.
✗ Branch 441 not taken.
✓ Branch 442 taken 1026 times.
✗ Branch 443 not taken.
✗ Branch 444 not taken.
✗ Branch 445 not taken.
✗ Branch 446 not taken.
✗ Branch 447 not taken.
✗ Branch 448 not taken.
✗ Branch 449 not taken.
✗ Branch 450 not taken.
✗ Branch 451 not taken.
✗ Branch 452 not taken.
✗ Branch 453 not taken.
✗ Branch 454 not taken.
✗ Branch 455 not taken.
✗ Branch 456 not taken.
✗ Branch 457 not taken.
✗ Branch 458 not taken.
✗ Branch 459 not taken.
✗ Branch 460 not taken.
✗ Branch 461 not taken.
✗ Branch 462 not taken.
✗ Branch 463 not taken.
✗ Branch 464 not taken.
✗ Branch 465 not taken.
✗ Branch 466 not taken.
✗ Branch 467 not taken.
✗ Branch 468 not taken.
✗ Branch 469 not taken.
✗ Branch 470 not taken.
✗ Branch 471 not taken.
✓ Branch 472 taken 17 times.
✗ Branch 473 not taken.
✗ Branch 474 not taken.
✗ Branch 475 not taken.
✓ Branch 476 taken 910 times.
✗ Branch 477 not taken.
✗ Branch 478 not taken.
✓ Branch 479 taken 9492 times.
✓ Branch 480 taken 43250 times.
✗ Branch 481 not taken.
✓ Branch 482 taken 6 times.
✗ Branch 483 not taken.
✗ Branch 484 not taken.
✗ Branch 485 not taken.
✗ Branch 486 not taken.
✗ Branch 487 not taken.
✓ Branch 488 taken 10246 times.
✓ Branch 489 taken 7214 times.
✓ Branch 490 taken 2391 times.
✓ Branch 491 taken 25369889 times.
✓ Branch 492 taken 47 times.
✓ Branch 493 taken 2 times.
✓ Branch 494 taken 343159 times.
✓ Branch 495 taken 100950 times.
✗ Branch 496 not taken.
✗ Branch 497 not taken.
✗ Branch 498 not taken.
✓ Branch 499 taken 1636 times.
✓ Branch 500 taken 1610 times.
✓ Branch 501 taken 32 times.
✗ Branch 502 not taken.
✗ Branch 503 not taken.
✗ Branch 504 not taken.
✓ Branch 505 taken 16 times.
✗ Branch 506 not taken.
✓ Branch 507 taken 16 times.
✗ Branch 508 not taken.
✓ Branch 509 taken 16 times.
✓ Branch 510 taken 16 times.
✗ Branch 511 not taken.
✗ Branch 512 not taken.
✓ Branch 513 taken 6567172 times.
✓ Branch 514 taken 3858 times.
✓ Branch 515 taken 192 times.
✗ Branch 516 not taken.
✗ Branch 517 not taken.
✗ Branch 518 not taken.
✗ Branch 519 not taken.
✗ Branch 520 not taken.
✗ Branch 521 not taken.
✗ Branch 522 not taken.
✗ Branch 523 not taken.
✗ Branch 524 not taken.
✗ Branch 525 not taken.
✗ Branch 526 not taken.
✗ Branch 527 not taken.
✓ Branch 528 taken 192 times.
✗ Branch 529 not taken.
✗ Branch 530 not taken.
✗ Branch 531 not taken.
✗ Branch 532 not taken.
✗ Branch 533 not taken.
✗ Branch 534 not taken.
✗ Branch 535 not taken.
✗ Branch 536 not taken.
✗ Branch 537 not taken.
✗ Branch 538 not taken.
✗ Branch 539 not taken.
✗ Branch 540 not taken.
✗ Branch 541 not taken.
✗ Branch 542 not taken.
✗ Branch 543 not taken.
✗ Branch 544 not taken.
✗ Branch 545 not taken.
✗ Branch 546 not taken.
✗ Branch 547 not taken.
✗ Branch 548 not taken.
✗ Branch 549 not taken.
✗ Branch 550 not taken.
✓ Branch 551 taken 32 times.
✓ Branch 552 taken 2004 times.
✗ Branch 553 not taken.
✗ Branch 554 not taken.
✗ Branch 555 not taken.
✗ Branch 556 not taken.
✗ Branch 557 not taken.
✗ Branch 558 not taken.
✗ Branch 559 not taken.
✗ Branch 560 not taken.
✗ Branch 561 not taken.
✓ Branch 562 taken 9 times.
✓ Branch 563 taken 21 times.
✗ Branch 564 not taken.
✗ Branch 565 not taken.
✗ Branch 566 not taken.
✗ Branch 567 not taken.
✓ Branch 568 taken 701 times.
✓ Branch 569 taken 225 times.
✗ Branch 570 not taken.
✓ Branch 571 taken 6 times.
✗ Branch 572 not taken.
✓ Branch 573 taken 212 times.
✓ Branch 574 taken 19 times.
✗ Branch 575 not taken.
✓ Branch 576 taken 1124 times.
✓ Branch 577 taken 1095768 times.
✗ Branch 578 not taken.
✗ Branch 579 not taken.
✓ Branch 580 taken 5120 times.
✗ Branch 581 not taken.
✗ Branch 582 not taken.
✗ Branch 583 not taken.
✗ Branch 584 not taken.
✗ Branch 585 not taken.
✗ Branch 586 not taken.
✗ Branch 587 not taken.
✗ Branch 588 not taken.
✗ Branch 589 not taken.
✓ Branch 590 taken 22016 times.
✗ Branch 591 not taken.
✗ Branch 592 not taken.
✗ Branch 593 not taken.
✗ Branch 594 not taken.
✗ Branch 595 not taken.
✗ Branch 596 not taken.
✗ Branch 597 not taken.
✗ Branch 598 not taken.
✗ Branch 599 not taken.
✗ Branch 600 not taken.
✗ Branch 601 not taken.
✗ Branch 602 not taken.
✗ Branch 603 not taken.
✗ Branch 604 not taken.
✗ Branch 605 not taken.
✗ Branch 606 not taken.
✗ Branch 607 not taken.
✗ Branch 608 not taken.
✗ Branch 609 not taken.
✗ Branch 610 not taken.
✗ Branch 611 not taken.
✗ Branch 612 not taken.
✗ Branch 613 not taken.
✗ Branch 614 not taken.
✗ Branch 615 not taken.
✓ Branch 616 taken 60340 times.
✓ Branch 617 taken 12211 times.
✓ Branch 618 taken 208371 times.
✓ Branch 619 taken 19038 times.
✓ Branch 620 taken 116988 times.
✓ Branch 621 taken 112420 times.
✗ Branch 622 not taken.
✗ Branch 623 not taken.
✗ Branch 624 not taken.
✓ Branch 625 taken 4546 times.
✓ Branch 626 taken 6890 times.
✓ Branch 627 taken 755 times.
✓ Branch 628 taken 5110 times.
✗ Branch 629 not taken.
✗ Branch 630 not taken.
✗ Branch 631 not taken.
✓ Branch 632 taken 463074 times.
✗ Branch 633 not taken.
✗ Branch 634 not taken.
✗ Branch 635 not taken.
✗ Branch 636 not taken.
✗ Branch 637 not taken.
✗ Branch 638 not taken.
✗ Branch 639 not taken.
✗ Branch 640 not taken.
✓ Branch 641 taken 18 times.
✗ Branch 642 not taken.
✗ Branch 643 not taken.
✗ Branch 644 not taken.
✗ Branch 645 not taken.
✗ Branch 646 not taken.
✗ Branch 647 not taken.
✗ Branch 648 not taken.
✗ Branch 649 not taken.
✗ Branch 650 not taken.
✗ Branch 651 not taken.
✗ Branch 652 not taken.
✗ Branch 653 not taken.
✗ Branch 654 not taken.
✗ Branch 655 not taken.
✗ Branch 656 not taken.
✓ Branch 657 taken 25 times.
✗ Branch 658 not taken.
✗ Branch 659 not taken.
✗ Branch 660 not taken.
✗ Branch 661 not taken.
✗ Branch 662 not taken.
✗ Branch 663 not taken.
✗ Branch 664 not taken.
✗ Branch 665 not taken.
✗ Branch 666 not taken.
✗ Branch 667 not taken.
✗ Branch 668 not taken.
✗ Branch 669 not taken.
✗ Branch 670 not taken.
✗ Branch 671 not taken.
✗ Branch 672 not taken.
✗ Branch 673 not taken.
✗ Branch 674 not taken.
✗ Branch 675 not taken.
✗ Branch 676 not taken.
✗ Branch 677 not taken.
✗ Branch 678 not taken.
✗ Branch 679 not taken.
✗ Branch 680 not taken.
✗ Branch 681 not taken.
✗ Branch 682 not taken.
✗ Branch 683 not taken.
✗ Branch 684 not taken.
✗ Branch 685 not taken.
✗ Branch 686 not taken.
✗ Branch 687 not taken.
✗ Branch 688 not taken.
✗ Branch 689 not taken.
✗ Branch 690 not taken.
✗ Branch 691 not taken.
✗ Branch 692 not taken.
✗ Branch 693 not taken.
✗ Branch 694 not taken.
✗ Branch 695 not taken.
✗ Branch 696 not taken.
✗ Branch 697 not taken.
✓ Branch 698 taken 11602 times.
✗ Branch 699 not taken.
✗ Branch 700 not taken.
✗ Branch 701 not taken.
✗ Branch 702 not taken.
✗ Branch 703 not taken.
✗ Branch 704 not taken.
✗ Branch 705 not taken.
✗ Branch 706 not taken.
✗ Branch 707 not taken.
✗ Branch 708 not taken.
✗ Branch 709 not taken.
✗ Branch 710 not taken.
✗ Branch 711 not taken.
✗ Branch 712 not taken.
✗ Branch 713 not taken.
✗ Branch 714 not taken.
✗ Branch 715 not taken.
✗ Branch 716 not taken.
✗ Branch 717 not taken.
✗ Branch 718 not taken.
✗ Branch 719 not taken.
✗ Branch 720 not taken.
✗ Branch 721 not taken.
✗ Branch 722 not taken.
✗ Branch 723 not taken.
✗ Branch 724 not taken.
✗ Branch 725 not taken.
✗ Branch 726 not taken.
✗ Branch 727 not taken.
✗ Branch 728 not taken.
✗ Branch 729 not taken.
✗ Branch 730 not taken.
✗ Branch 731 not taken.
✗ Branch 732 not taken.
✗ Branch 733 not taken.
✗ Branch 734 not taken.
✗ Branch 735 not taken.
✗ Branch 736 not taken.
✗ Branch 737 not taken.
✗ Branch 738 not taken.
✗ Branch 739 not taken.
✗ Branch 740 not taken.
✗ Branch 741 not taken.
✗ Branch 742 not taken.
✗ Branch 743 not taken.
✗ Branch 744 not taken.
✗ Branch 745 not taken.
✗ Branch 746 not taken.
✗ Branch 747 not taken.
✗ Branch 748 not taken.
✗ Branch 749 not taken.
✗ Branch 750 not taken.
✗ Branch 751 not taken.
✗ Branch 752 not taken.
✗ Branch 753 not taken.
✗ Branch 754 not taken.
✗ Branch 755 not taken.
✗ Branch 756 not taken.
✗ Branch 757 not taken.
✗ Branch 758 not taken.
✗ Branch 759 not taken.
✗ Branch 760 not taken.
✗ Branch 761 not taken.
✗ Branch 762 not taken.
✗ Branch 763 not taken.
✗ Branch 764 not taken.
✗ Branch 765 not taken.
✗ Branch 766 not taken.
✗ Branch 767 not taken.
✗ Branch 768 not taken.
✗ Branch 769 not taken.
✗ Branch 770 not taken.
✗ Branch 771 not taken.
✗ Branch 772 not taken.
✗ Branch 773 not taken.
✗ Branch 774 not taken.
✗ Branch 775 not taken.
✗ Branch 776 not taken.
✗ Branch 777 not taken.
✗ Branch 778 not taken.
✗ Branch 779 not taken.
✗ Branch 780 not taken.
✗ Branch 781 not taken.
✗ Branch 782 not taken.
✗ Branch 783 not taken.
✗ Branch 784 not taken.
✗ Branch 785 not taken.
✗ Branch 786 not taken.
✗ Branch 787 not taken.
✗ Branch 788 not taken.
✗ Branch 789 not taken.
✗ Branch 790 not taken.
✗ Branch 791 not taken.
✗ Branch 792 not taken.
✗ Branch 793 not taken.
✗ Branch 794 not taken.
✗ Branch 795 not taken.
✗ Branch 796 not taken.
✗ Branch 797 not taken.
✗ Branch 798 not taken.
✗ Branch 799 not taken.
✗ Branch 800 not taken.
✗ Branch 801 not taken.
✗ Branch 802 not taken.
✗ Branch 803 not taken.
✗ Branch 804 not taken.
✗ Branch 805 not taken.
✗ Branch 806 not taken.
✗ Branch 807 not taken.
✗ Branch 808 not taken.
✗ Branch 809 not taken.
✗ Branch 810 not taken.
✗ Branch 811 not taken.
✗ Branch 812 not taken.
✗ Branch 813 not taken.
✗ Branch 814 not taken.
✗ Branch 815 not taken.
✗ Branch 816 not taken.
✗ Branch 817 not taken.
✗ Branch 818 not taken.
✗ Branch 819 not taken.
✗ Branch 820 not taken.
✗ Branch 821 not taken.
✗ Branch 822 not taken.
✗ Branch 823 not taken.
✗ Branch 824 not taken.
✗ Branch 825 not taken.
✓ Branch 826 taken 3182 times.
✗ Branch 827 not taken.
✗ Branch 828 not taken.
✗ Branch 829 not taken.
✗ Branch 830 not taken.
✓ Branch 831 taken 3182 times.
✗ Branch 832 not taken.
✗ Branch 833 not taken.
✗ Branch 834 not taken.
✗ Branch 835 not taken.
✗ Branch 836 not taken.
✗ Branch 837 not taken.
✗ Branch 838 not taken.
✗ Branch 839 not taken.
✗ Branch 840 not taken.
✗ Branch 841 not taken.
✗ Branch 842 not taken.
✗ Branch 843 not taken.
✗ Branch 844 not taken.
✗ Branch 845 not taken.
✗ Branch 846 not taken.
✓ Branch 847 taken 1 times.
✗ Branch 848 not taken.
✗ Branch 849 not taken.
✗ Branch 850 not taken.
✗ Branch 851 not taken.
✗ Branch 852 not taken.
✗ Branch 853 not taken.
✗ Branch 854 not taken.
✗ Branch 855 not taken.
✗ Branch 856 not taken.
✗ Branch 857 not taken.
✗ Branch 858 not taken.
✗ Branch 859 not taken.
✗ Branch 860 not taken.
✗ Branch 861 not taken.
✗ Branch 862 not taken.
✗ Branch 863 not taken.
✗ Branch 864 not taken.
✗ Branch 865 not taken.
✗ Branch 866 not taken.
✗ Branch 867 not taken.
✗ Branch 868 not taken.
✗ Branch 869 not taken.
✓ Branch 870 taken 10 times.
✗ Branch 871 not taken.
✓ Branch 872 taken 3453 times.
✗ Branch 873 not taken.
✗ Branch 874 not taken.
✗ Branch 875 not taken.
✗ Branch 876 not taken.
✗ Branch 877 not taken.
✗ Branch 878 not taken.
✗ Branch 879 not taken.
✓ Branch 880 taken 26646 times.
✓ Branch 881 taken 608463 times.
✓ Branch 882 taken 5613429 times.
✓ Branch 883 taken 1561195 times.
✓ Branch 884 taken 4923553 times.
✓ Branch 885 taken 27873688 times.
✗ Branch 886 not taken.
✗ Branch 887 not taken.
✓ Branch 888 taken 20 times.
✓ Branch 889 taken 215684 times.
✗ Branch 890 not taken.
✓ Branch 891 taken 16 times.
✓ Branch 892 taken 10 times.
✓ Branch 893 taken 1 times.
✓ Branch 894 taken 72922 times.
✗ Branch 895 not taken.
✓ Branch 896 taken 24 times.
✓ Branch 897 taken 10 times.
✗ Branch 898 not taken.
✗ Branch 899 not taken.
✓ Branch 900 taken 137701 times.
✗ Branch 901 not taken.
✗ Branch 902 not taken.
✗ Branch 903 not taken.
✓ Branch 904 taken 36 times.
✗ Branch 905 not taken.
✗ Branch 906 not taken.
✗ Branch 907 not taken.
✗ Branch 908 not taken.
✓ Branch 909 taken 6280 times.
✓ Branch 910 taken 1113 times.
✗ Branch 911 not taken.
✓ Branch 912 taken 8 times.
✓ Branch 913 taken 63 times.
✗ Branch 914 not taken.
✓ Branch 915 taken 5 times.
✗ Branch 916 not taken.
✓ Branch 917 taken 5487 times.
✗ Branch 918 not taken.
✗ Branch 919 not taken.
✗ Branch 920 not taken.
✗ Branch 921 not taken.
✗ Branch 922 not taken.
✗ Branch 923 not taken.
✗ Branch 924 not taken.
✗ Branch 925 not taken.
✗ Branch 926 not taken.
✗ Branch 927 not taken.
✗ Branch 928 not taken.
✗ Branch 929 not taken.
✗ Branch 930 not taken.
✗ Branch 931 not taken.
✗ Branch 932 not taken.
✗ Branch 933 not taken.
✗ Branch 934 not taken.
✗ Branch 935 not taken.
✗ Branch 936 not taken.
✗ Branch 937 not taken.
✗ Branch 938 not taken.
✗ Branch 939 not taken.
✗ Branch 940 not taken.
✗ Branch 941 not taken.
✗ Branch 942 not taken.
✗ Branch 943 not taken.
✗ Branch 944 not taken.
✗ Branch 945 not taken.
✗ Branch 946 not taken.
✓ Branch 947 taken 14124 times.
✗ Branch 948 not taken.
✗ Branch 949 not taken.
✗ Branch 950 not taken.
✓ Branch 951 taken 54674 times.
✓ Branch 952 taken 11 times.
✗ Branch 953 not taken.
✗ Branch 954 not taken.
✗ Branch 955 not taken.
✗ Branch 956 not taken.
✗ Branch 957 not taken.
✗ Branch 958 not taken.
✗ Branch 959 not taken.
✗ Branch 960 not taken.
✗ Branch 961 not taken.
✗ Branch 962 not taken.
✓ Branch 963 taken 5031 times.
✗ Branch 964 not taken.
✗ Branch 965 not taken.
✗ Branch 966 not taken.
✗ Branch 967 not taken.
✓ Branch 968 taken 1005 times.
✗ Branch 969 not taken.
✓ Branch 970 taken 17326 times.
✓ Branch 971 taken 6024 times.
✗ Branch 972 not taken.
✓ Branch 973 taken 4206 times.
✓ Branch 974 taken 9836 times.
✗ Branch 975 not taken.
✗ Branch 976 not taken.
✓ Branch 977 taken 339 times.
✓ Branch 978 taken 339 times.
✗ Branch 979 not taken.
✗ Branch 980 not taken.
✗ Branch 981 not taken.
✗ Branch 982 not taken.
✗ Branch 983 not taken.
✗ Branch 984 not taken.
✗ Branch 985 not taken.
✗ Branch 986 not taken.
✗ Branch 987 not taken.
✗ Branch 988 not taken.
✗ Branch 989 not taken.
✗ Branch 990 not taken.
✗ Branch 991 not taken.
✗ Branch 992 not taken.
✗ Branch 993 not taken.
✗ Branch 994 not taken.
✗ Branch 995 not taken.
✗ Branch 996 not taken.
✗ Branch 997 not taken.
✗ Branch 998 not taken.
✗ Branch 999 not taken.
✗ Branch 1000 not taken.
✗ Branch 1001 not taken.
✗ Branch 1002 not taken.
✗ Branch 1003 not taken.
✗ Branch 1004 not taken.
✗ Branch 1005 not taken.
✗ Branch 1006 not taken.
✗ Branch 1007 not taken.
✗ Branch 1008 not taken.
✗ Branch 1009 not taken.
✗ Branch 1010 not taken.
✗ Branch 1011 not taken.
✗ Branch 1012 not taken.
✗ Branch 1013 not taken.
✗ Branch 1014 not taken.
✗ Branch 1015 not taken.
✗ Branch 1016 not taken.
✗ Branch 1017 not taken.
✗ Branch 1018 not taken.
✗ Branch 1019 not taken.
✗ Branch 1020 not taken.
✗ Branch 1021 not taken.
✓ Branch 1022 taken 1455 times.
✗ Branch 1023 not taken.
✗ Branch 1024 not taken.
✗ Branch 1025 not taken.
✗ Branch 1026 not taken.
✗ Branch 1027 not taken.
✗ Branch 1028 not taken.
✗ Branch 1029 not taken.
✗ Branch 1030 not taken.
✗ Branch 1031 not taken.
✗ Branch 1032 not taken.
✗ Branch 1033 not taken.
✗ Branch 1034 not taken.
✗ Branch 1035 not taken.
✗ Branch 1036 not taken.
✗ Branch 1037 not taken.
✗ Branch 1038 not taken.
✗ Branch 1039 not taken.
✗ Branch 1040 not taken.
✗ Branch 1041 not taken.
✗ Branch 1042 not taken.
✗ Branch 1043 not taken.
✗ Branch 1044 not taken.
2846222550 switch(arg)
3217 {
3218 case MAX_FFC_ID:
3219 {
3220 3175230 ret = (MAX_FFCID + 1) * 10000;
3221 3175230 break;
3222 }
3223
3224 case INCQST:
3225 {
3226 int32_t newqst = 0;
3227 if ( game->get_quest() < 255 ) //255 is a custom quest
3228 {
3229 newqst = (game->get_quest()+1);
3230 }
3231 else
3232 {
3233 newqst = 1;
3234 }
3235 if ( newqst < 11 )
3236 {
3237
3238 ret = newqst * 10000;
3239 Quit = qINCQST;
3240 //ending();
3241
3242 }
3243 else ret = -10000;
3244 break;
3245 }
3246 case DEBUGTESTING:
3247 623627 ret = use_testingst_start ? 10000 : 0;
3248 623627 break;
3249
3250 ///----------------------------------------------------------------------------------------------------//
3251 //FFC Variables
3252 case DATA:
3253
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 13052060 times.
13052062 if (auto ffc = ResolveFFC(ri->ffcref))
3254 13052060 ret = ffc->data * 10000;
3255 13052062 break;
3256
3257 case FFSCRIPT:
3258
2/2
✓ Branch 0 taken 212 times.
✓ Branch 1 taken 531424776 times.
531424988 if(auto ffc = ResolveFFC(ri->ffcref))
3259 531424776 ret = ffc->script * 10000;
3260 531424988 break;
3261
3262 case FCSET:
3263
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2312685 times.
2312685 if(auto ffc = ResolveFFC(ri->ffcref))
3264 2312685 ret = ffc->cset * 10000;
3265 2312685 break;
3266
3267 case DELAY:
3268
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(auto ffc = ResolveFFC(ri->ffcref))
3269 10 ret = ffc->delay * 10000;
3270 10 break;
3271
3272 case FX:
3273
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24185371 times.
24185371 if(auto ffc = ResolveFFC(ri->ffcref))
3274 24185371 ret = ffc->x.getZLong();
3275 24185371 break;
3276
3277 case FY:
3278
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23746251 times.
23746251 if(auto ffc = ResolveFFC(ri->ffcref))
3279 23746251 ret = ffc->y.getZLong();
3280 23746251 break;
3281
3282 case XD:
3283
1/2
✓ Branch 0 taken 5823966 times.
✗ Branch 1 not taken.
5823966 if(auto ffc = ResolveFFC(ri->ffcref))
3284 5823966 ret = ffc->vx.getZLong();
3285 5823966 break;
3286
3287 case YD:
3288
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 163102 times.
163102 if(auto ffc = ResolveFFC(ri->ffcref))
3289 163102 ret = ffc->vy.getZLong();
3290 163102 break;
3291 case FFCID:
3292
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 375 times.
375 if (auto ffc = ResolveFFC(ri->ffcref))
3293 375 ret = (get_region_screen_offset(ffc->screen_spawned) * MAXFFCS + ffc->index + 1) * 10000;
3294 375 break;
3295
3296 case XD2:
3297
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 if(auto ffc = ResolveFFC(ri->ffcref))
3298 51 ret = ffc->ax.getZLong();
3299 51 break;
3300
3301 case YD2:
3302
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if(auto ffc = ResolveFFC(ri->ffcref))
3303 51 ret = ffc->ay.getZLong();
3304 51 break;
3305
3306 case FFCWIDTH:
3307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 204076 times.
204076 if(auto ffc = ResolveFFC(ri->ffcref))
3308 204076 ret = ffc->hit_width * 10000;
3309 204076 break;
3310
3311 case FFCHEIGHT:
3312
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 199035 times.
199035 if(auto ffc = ResolveFFC(ri->ffcref))
3313 199035 ret = ffc->hit_height * 10000;
3314 199035 break;
3315
3316 case FFTWIDTH:
3317
1/2
✓ Branch 0 taken 5283857 times.
✗ Branch 1 not taken.
5283857 if(auto ffc = ResolveFFC(ri->ffcref))
3318 5283857 ret = ffc->txsz * 10000;
3319 5283857 break;
3320
3321 case FFTHEIGHT:
3322
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5194596 times.
5194596 if(auto ffc = ResolveFFC(ri->ffcref))
3323 5194596 ret = ffc->tysz * 10000;
3324 5194596 break;
3325
3326 case FFCLAYER:
3327 if (auto ffc = ResolveFFC(ri->ffcref))
3328 ret = ffc->layer * 10000;
3329 break;
3330
3331 case FFLINK:
3332 if(auto ffc = ResolveFFC(ri->ffcref))
3333 ret = ffc->link * 10000;
3334 break;
3335
3336 ///----------------------------------------------------------------------------------------------------//
3337 //Hero's Variables
3338 case LINKX:
3339 {
3340
2/2
✓ Branch 0 taken 8938966 times.
✓ Branch 1 taken 32842205 times.
41781171 if (get_qr(qr_SPRITEXY_IS_FLOAT))
3341 {
3342 8938966 ret = Hero.getX().getZLong();
3343 8938966 }
3344 32842205 else ret = int32_t(Hero.getX()) * 10000;
3345
3346 41781171 break;
3347 }
3348
3349 case LINKCSET:
3350 {
3351 ret = Hero.cs * 10000;
3352 break;
3353 }
3354 case LINKY:
3355 {
3356
2/2
✓ Branch 0 taken 9752728 times.
✓ Branch 1 taken 32915641 times.
42668369 if (get_qr(qr_SPRITEXY_IS_FLOAT))
3357 {
3358 9752728 ret = Hero.getY().getZLong();
3359 9752728 }
3360 32915641 else ret = int32_t(Hero.getY()) * 10000;
3361
3362 42668369 break;
3363 }
3364 case LINKZ:
3365 {
3366
2/2
✓ Branch 0 taken 2847194 times.
✓ Branch 1 taken 1173487 times.
4020681 if (get_qr(qr_SPRITEXY_IS_FLOAT))
3367 {
3368 2847194 ret = Hero.getZ().getZLong();
3369 2847194 }
3370 1173487 else ret = int32_t(Hero.getZ()) * 10000;
3371
3372 4020681 break;
3373 }
3374 case LINKJUMP:
3375 719568 ret = Hero.getJump().getZLong();
3376 719568 break;
3377
3378 case HEROFAKEJUMP:
3379 ret = Hero.getFakeJump().getZLong() / -100;
3380 break;
3381
3382 case LINKDIR:
3383 9094315 ret=(int32_t)(Hero.dir)*10000;
3384 9094315 break;
3385
3386 case LINKHITDIR:
3387 441276 ret=(int32_t)(Hero.getHitDir())*10000;
3388 441276 break;
3389
3390 case LINKHP:
3391 24133498 ret=(int32_t)(game->get_life())*10000;
3392 24133498 break;
3393
3394 case LINKGRAVITY:
3395 ret = ( (Hero.moveflags & move_obeys_grav) ? 10000 : 0 );
3396 break;
3397
3398 case HERONOSTEPFORWARD:
3399 ret = ( (FFCore.nostepforward) ? 10000 : 0 );
3400 break;
3401
3402 case LINKMP:
3403 2790135 ret=(int32_t)(game->get_magic())*10000;
3404 2790135 break;
3405
3406 case LINKMAXHP:
3407 1061314 ret=(int32_t)(game->get_maxlife())*10000;
3408 1061314 break;
3409
3410 case LINKMAXMP:
3411 944827 ret=(int32_t)(game->get_maxmagic())*10000;
3412 944827 break;
3413
3414 case LINKACTION:
3415 {
3416 78367192 ret = FFCore.getHeroAction() * 10000;
3417 78367192 break;
3418 }
3419
3420 case HEROHEALTHBEEP:
3421 {
3422 ret = heart_beep ? ( heart_beep_timer * 10000 ) : 0;
3423 break;
3424 }
3425
3426 case LINKHELD:
3427 204 ret = (int32_t)(Hero.getHeldItem())*10000;
3428 204 break;
3429
3430 case HEROSTEPRATE:
3431 5424 ret = Hero.getStepRate() * 10000;
3432 5424 break;
3433 case HEROSHOVEOFFSET:
3434 ret = Hero.shove_offset.getZLong();
3435 break;
3436
3437 case LINKEQUIP:
3438 1249005 ret = ((Awpn&0xFF)|((Bwpn&0xFF)<<8))*10000;
3439 1249005 break;
3440
3441 case LINKINVIS:
3442 573955 ret = (((int32_t)(Hero.getDontDraw())) ? 10000 : 0);
3443 573955 break;
3444
3445 case LINKINVINC:
3446 652486 ret = (int32_t)(Hero.scriptcoldet)*10000;
3447 652486 break;
3448
3449 case LINKENGINEANIMATE:
3450 ret = (int32_t)(Hero.do_animation)*10000;
3451 break;
3452
3453 case LINKLADDERX:
3454 ret=(int32_t)(Hero.getLadderX())*10000;
3455 break;
3456
3457 case LINKLADDERY:
3458 ret=(int32_t)(Hero.getLadderY())*10000;
3459 break;
3460
3461 case LINKSWORDJINX:
3462 959935 ret = (int32_t)(Hero.getSwordClk())*10000;
3463 959935 break;
3464
3465 case LINKITEMJINX:
3466 1095514 ret = (int32_t)(Hero.getItemClk())*10000;
3467 1095514 break;
3468
3469 case LINKDRUNK:
3470 ret = (int32_t)(Hero.DrunkClock())*10000;
3471 break;
3472
3473 case LINKROTATION:
3474 if ( get_qr(qr_OLDSPRITEDRAWS) )
3475 {
3476 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
3477 ret = -1; break;
3478 }
3479 ret = (int32_t)(Hero.rotation)*10000;
3480 break;
3481
3482 case LINKSCALE:
3483 {
3484 if ( get_qr(qr_OLDSPRITEDRAWS) )
3485 {
3486 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
3487 ret = -1; break;
3488 }
3489 ret = (int32_t)(Hero.scale*100.0);
3490 break;
3491 }
3492
3493
3494 case LINKHXOFS:
3495 656387 ret = (int32_t)(Hero.hxofs)*10000;
3496 656387 break;
3497
3498 case LINKHYOFS:
3499 571655 ret = (int32_t)(Hero.hyofs)*10000;
3500 571655 break;
3501
3502 case LINKXOFS:
3503 113145 ret = (int32_t)(Hero.xofs)*10000;
3504 113145 break;
3505
3506 case LINKYOFS:
3507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115547 times.
115547 ret = (int32_t)(Hero.yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset))*10000;
3508 115547 break;
3509
3510 case HEROSHADOWXOFS:
3511 ret = (int32_t)(Hero.shadowxofs)*10000;
3512 break;
3513
3514 case HEROSHADOWYOFS:
3515 ret = (int32_t)(Hero.shadowyofs)*10000;
3516 break;
3517
3518 case HEROTOTALDYOFFS:
3519 ret = 10000*(((int32_t)(Hero.yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset)))
3520 + ((Hero.switch_hooked && Hero.switchhookstyle == swRISE)
3521 ? -(8-(abs(Hero.switchhookclk-32)/4)) : 0));
3522 break;
3523
3524 case LINKZOFS:
3525 ret = (int32_t)(Hero.zofs)*10000;
3526 break;
3527
3528 case LINKHXSZ:
3529 489104 ret = (int32_t)(Hero.hit_width)*10000;
3530 489104 break;
3531
3532 case LINKHYSZ:
3533 489104 ret = (int32_t)(Hero.hit_height)*10000;
3534 489104 break;
3535
3536 case LINKHZSZ:
3537 288295 ret = (int32_t)(Hero.hzsz)*10000;
3538 288295 break;
3539
3540 case LINKTXSZ:
3541 ret = (int32_t)(Hero.txsz)*10000;
3542 break;
3543
3544 case LINKTYSZ:
3545 ret = (int32_t)(Hero.tysz)*10000;
3546 break;
3547
3548 case LINKTILE:
3549 4101 ret = (int32_t)(Hero.tile)*10000;
3550 4101 break;
3551
3552 case LINKFLIP:
3553 ret = (int32_t)(Hero.flip)*10000;
3554 break;
3555
3556 case LINKINVFRAME:
3557 57322 ret = (int32_t)Hero.getHClk()*10000;
3558 57322 break;
3559
3560 case LINKCANFLICKER:
3561 ret= Hero.getCanFlicker()?10000:0;
3562 break;
3563 case LINKHURTSFX:
3564 ret = (int32_t)Hero.getHurtSFX()*10000;
3565 break;
3566
3567 /*
3568 case LINKUSINGITEM:
3569 ret = (int32_t)Hero.getDirectItem()*10000;
3570 break;
3571
3572 case LINKUSINGITEMA:
3573 ret = (int32_t)Hero.getDirectItemA()*10000;
3574 break;
3575
3576 case LINKUSINGITEMB:
3577 ret = (int32_t)Hero.getDirectItemB()*10000;
3578 break;
3579 */
3580
3581 case LINKEATEN:
3582 ret=(int32_t)Hero.getEaten()*10000;
3583 break;
3584 case LINKGRABBED:
3585 ret = Hero.inwallm ? 10000 : 0;
3586 break;
3587 case HEROBUNNY:
3588 ret = Hero.BunnyClock()*10000;
3589 break;
3590 case LINKPUSH:
3591 180367 ret=(int32_t)Hero.getPushing()*10000;
3592 180367 break;
3593 case LINKSTUN:
3594 440770 ret=(int32_t)Hero.StunClock()*10000;
3595 440770 break;
3596 case LINKSCRIPTTILE:
3597 2 ret=script_hero_sprite*10000;
3598 2 break;
3599
3600 case HEROSCRIPTCSET:
3601 ret=script_hero_cset*10000;
3602 break;
3603 case LINKSCRIPFLIP:
3604 ret=script_hero_flip*10000;
3605 break;
3606
3607
3608 case LINKITEMB:
3609 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
3610 428588 ret = Bwpn*10000;
3611 428588 break;
3612
3613 case LINKITEMA:
3614 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
3615 432590 ret = Awpn *10000;
3616 432590 break;
3617
3618 case LINKITEMX:
3619 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
3620 337110 ret = Xwpn *10000;
3621 337110 break;
3622
3623 case LINKITEMY:
3624 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
3625 273630 ret = Ywpn *10000;
3626 273630 break;
3627
3628 case LINKTILEMOD:
3629 ret = Hero.getTileModifier() * 10000;
3630 break;
3631
3632 case LINKDIAG:
3633 ret=Hero.getDiagMove()?10000:0;
3634 break;
3635
3636 case LINKBIGHITBOX:
3637 271788 ret=Hero.getBigHitbox()?10000:0;
3638 271788 break;
3639
3640 case LINKCLIMBING:
3641 ret = Hero.getOnSideviewLadder()?10000:0;
3642 break;
3643
3644 case HEROJUMPCOUNT:
3645 ret = Hero.extra_jump_count * 10000;
3646 break;
3647
3648 case HEROPULLDIR:
3649 ret = Hero.pit_pulldir * 10000;
3650 break;
3651
3652 case HEROPULLCLK:
3653 ret = Hero.pit_pullclk * 10000;
3654 break;
3655
3656 case HEROFALLCLK:
3657 832354 ret = Hero.fallclk * 10000;
3658 832354 break;
3659
3660 case HEROFALLCMB:
3661 18 ret = Hero.fallCombo * 10000;
3662 18 break;
3663
3664 case HERODROWNCLK:
3665 ret = Hero.drownclk * 10000;
3666 break;
3667
3668 case HERODROWNCMB:
3669 ret = Hero.drownCombo * 10000;
3670 break;
3671
3672 case HEROFAKEZ:
3673 {
3674
1/2
✓ Branch 0 taken 4357 times.
✗ Branch 1 not taken.
4357 if (get_qr(qr_SPRITEXY_IS_FLOAT))
3675 {
3676 4357 ret = Hero.getFakeZ().getZLong();
3677 4357 }
3678 else ret = int32_t(Hero.getFakeZ()) * 10000;
3679
3680 4357 break;
3681 }
3682
3683 case HEROSHIELDJINX:
3684 ret = Hero.shieldjinxclk * 10000;
3685 break;
3686
3687 case HEROISWARPING:
3688 1012 ret = Hero.is_warping ? 10000L : 0L;
3689 1012 break;
3690
3691 case CLOCKACTIVE:
3692 ret=watch?10000:0;
3693 break;
3694
3695 case CLOCKCLK:
3696 ret=clockclk*10000;
3697 break;
3698
3699 case HERORESPAWNX:
3700 {
3701 ret = Hero.respawn_x.getZLong();
3702 break;
3703 }
3704
3705 case HERORESPAWNY:
3706 {
3707 ret = Hero.respawn_y.getZLong();
3708 break;
3709 }
3710
3711 case HERORESPAWNDMAP:
3712 {
3713 ret = Hero.respawn_dmap * 10000;
3714 break;
3715 }
3716
3717 case HERORESPAWNSCR:
3718 {
3719 ret = Hero.respawn_scr * 10000;
3720 break;
3721 }
3722
3723 case HEROSWITCHTIMER:
3724 {
3725 ret = Hero.switchhookclk * 10000;
3726 break;
3727 }
3728
3729 case HEROSWITCHMAXTIMER:
3730 {
3731 ret = Hero.switchhookmaxtime * 10000;
3732 break;
3733 }
3734
3735 case HEROIMMORTAL:
3736 {
3737 ret = Hero.immortal * 10000;
3738 break;
3739 }
3740
3741 case HEROSTANDING:
3742 {
3743 ret = Hero.isStanding(true) ? 10000 : 0;
3744 break;
3745 }
3746
3747 case HEROCOYOTETIME:
3748 {
3749 ret = Hero.coyotetime*10000;
3750 break;
3751 }
3752
3753 case HEROLIFTEDWPN:
3754 {
3755 ret = Hero.lift_wpn ? Hero.lift_wpn->getUID() : 0;
3756 break;
3757 }
3758 case HEROLIFTTIMER:
3759 {
3760 ret = Hero.liftclk * 10000;
3761 break;
3762 }
3763 case HEROLIFTMAXTIMER:
3764 {
3765 ret = Hero.tliftclk * 10000;
3766 break;
3767 }
3768 case HEROLIFTHEIGHT:
3769 {
3770 ret = Hero.liftheight.getZLong();
3771 break;
3772 }
3773 case HEROHAMMERSTATE:
3774 {
3775 ret = Hero.getHammerState() * 10000;
3776 break;
3777 }
3778 case HEROFLICKERCOLOR:
3779 ret = (int32_t)(Hero.flickercolor) * 10000; break;
3780 case HEROFLASHINGCSET:
3781 136185 ret = (int32_t)(Hero.getFlashingCSet()) * 10000; break;
3782 case HEROFLICKERTRANSP:
3783 ret = (int32_t)(Hero.flickertransp) * 10000; break;
3784
3785 case HEROSLIDING:
3786 ret = Hero.sliding*10000; break;
3787 case HEROICECMB:
3788 ret = Hero.ice_combo*10000; break;
3789 case HEROSCRICECMB:
3790 ret = Hero.script_ice_combo*10000; break;
3791 case HEROICEVX:
3792 ret = Hero.ice_vx.getZLong(); break;
3793 case HEROICEVY:
3794 ret = Hero.ice_vy.getZLong(); break;
3795 case HEROICEENTRYFRAMES:
3796 ret = Hero.ice_entry_count*10000; break;
3797 case HEROICEENTRYMAXFRAMES:
3798 ret = Hero.ice_entry_mcount*10000; break;
3799
3800 ///----------------------------------------------------------------------------------------------------//
3801 //Input States
3802 case INPUTSTART:
3803 92967 ret=control_state[6]?10000:0;
3804 92967 break;
3805
3806 case INPUTMAP:
3807 4123 ret=control_state[9]?10000:0;
3808 4123 break;
3809
3810 case INPUTUP:
3811 4321356 ret=control_state[0]?10000:0;
3812 4321356 break;
3813
3814 case INPUTDOWN:
3815 3824036 ret=control_state[1]?10000:0;
3816 3824036 break;
3817
3818 case INPUTLEFT:
3819 4211785 ret=control_state[2]?10000:0;
3820 4211785 break;
3821
3822 case INPUTRIGHT:
3823 4388042 ret=control_state[3]?10000:0;
3824 4388042 break;
3825
3826 case INPUTA:
3827 6701954 ret=control_state[4]?10000:0;
3828 6701954 break;
3829
3830 case INPUTB:
3831 5699839 ret=control_state[5]?10000:0;
3832 5699839 break;
3833
3834 case INPUTL:
3835 3218568 ret=control_state[7]?10000:0;
3836 3218568 break;
3837
3838 case INPUTR:
3839 3214309 ret=control_state[8]?10000:0;
3840 3214309 break;
3841
3842 case INPUTEX1:
3843 120159 ret=control_state[10]?10000:0;
3844 120159 break;
3845
3846 case INPUTEX2:
3847 120450 ret=control_state[11]?10000:0;
3848 120450 break;
3849
3850 case INPUTEX3:
3851 23391 ret=control_state[12]?10000:0;
3852 23391 break;
3853
3854 case INPUTEX4:
3855 23391 ret=control_state[13]?10000:0;
3856 23391 break;
3857
3858 case INPUTAXISUP:
3859 ret=control_state[14]?10000:0;
3860 break;
3861
3862 case INPUTAXISDOWN:
3863 ret=control_state[15]?10000:0;
3864 break;
3865
3866 case INPUTAXISLEFT:
3867 ret=control_state[16]?10000:0;
3868 break;
3869
3870 case INPUTAXISRIGHT:
3871 ret=control_state[17]?10000:0;
3872 break;
3873
3874 case INPUTMOUSEX:
3875 {
3876 791031 ret=get_mouse_state(0)*10000;
3877 791031 break;
3878 }
3879
3880 case INPUTMOUSEY:
3881 {
3882 791031 int32_t mousequakeoffset = 56+((int32_t)(zc::math::Sin((double)(quakeclk*int64_t(2)-frame))*4));
3883
3/4
✓ Branch 0 taken 24219 times.
✓ Branch 1 taken 766812 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 766812 times.
791031 int32_t tempoffset = (quakeclk > 0) ? mousequakeoffset : (get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset);
3884 791031 ret=((get_mouse_state(1)-tempoffset))*10000;
3885 791031 break;
3886 }
3887
3888 case INPUTMOUSEZ:
3889 ret=(get_mouse_state(2))*10000;
3890 break;
3891
3892 case INPUTMOUSEB:
3893 1073638 ret=(get_mouse_state(3))*10000;
3894 1073638 break;
3895
3896 case INPUTPRESSSTART:
3897 818518 ret=button_press[6]?10000:0;
3898 818518 break;
3899
3900 case INPUTPRESSMAP:
3901 335732 ret=button_press[9]?10000:0;
3902 335732 break;
3903
3904 case INPUTPRESSUP:
3905 1118025 ret=button_press[0]?10000:0;
3906 1118025 break;
3907
3908 case INPUTPRESSDOWN:
3909 1056398 ret=button_press[1]?10000:0;
3910 1056398 break;
3911
3912 case INPUTPRESSLEFT:
3913 963357 ret=button_press[2]?10000:0;
3914 963357 break;
3915
3916 case INPUTPRESSRIGHT:
3917 870340 ret=button_press[3]?10000:0;
3918 870340 break;
3919
3920 case INPUTPRESSA:
3921 2442823 ret=button_press[4]?10000:0;
3922 2442823 break;
3923
3924 case INPUTPRESSB:
3925 1811399 ret=button_press[5]?10000:0;
3926 1811399 break;
3927
3928 case INPUTPRESSL:
3929 2061226 ret=button_press[7]?10000:0;
3930 2061226 break;
3931
3932 case INPUTPRESSR:
3933 1845780 ret=button_press[8]?10000:0;
3934 1845780 break;
3935
3936 case INPUTPRESSEX1:
3937 1237553 ret=button_press[10]?10000:0;
3938 1237553 break;
3939
3940 case INPUTPRESSEX2:
3941 1081361 ret=button_press[11]?10000:0;
3942 1081361 break;
3943
3944 case INPUTPRESSEX3:
3945 558264 ret=button_press[12]?10000:0;
3946 558264 break;
3947
3948 case INPUTPRESSEX4:
3949 669416 ret=button_press[13]?10000:0;
3950 669416 break;
3951
3952 case PRESSAXISUP:
3953 ret=button_press[14]?10000:0;
3954 break;
3955
3956 case PRESSAXISDOWN:
3957 ret=button_press[15]?10000:0;
3958 break;
3959
3960 case PRESSAXISLEFT:
3961 ret=button_press[16]?10000:0;
3962 break;
3963
3964 case PRESSAXISRIGHT:
3965 ret=button_press[17]?10000:0;
3966 break;
3967
3968 case KEYMODIFIERS:
3969 {
3970 ret = (key_shifts*10000);
3971 break;
3972 }
3973
3974 ///----------------------------------------------------------------------------------------------------//
3975 //Itemdata Variables
3976
3977
3978 case IDATAUSEWPN:
3979 if(unsigned(ri->idata) >= MAXITEMS)
3980 {
3981 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3982 ret = -10000;
3983 break;
3984 }
3985 ret=(itemsbuf[ri->idata].useweapon)*10000;
3986 break;
3987 case IDATAUSEDEF:
3988 if(unsigned(ri->idata) >= MAXITEMS)
3989 {
3990 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
3991 ret = -10000;
3992 break;
3993 }
3994 ret=(itemsbuf[ri->idata].usedefense)*10000;
3995 break;
3996 case IDATAWRANGE:
3997 if(unsigned(ri->idata) >= MAXITEMS)
3998 {
3999 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4000 ret = -10000;
4001 break;
4002 }
4003 ret=(itemsbuf[ri->idata].weaprange)*10000;
4004 break;
4005 case IDATAMAGICTIMER:
4006 if(unsigned(ri->idata) >= MAXITEMS)
4007 {
4008 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4009 ret = -10000;
4010 break;
4011 }
4012 ret=(itemsbuf[ri->idata].magiccosttimer[0])*10000;
4013 break;
4014 case IDATAMAGICTIMER2:
4015 if(unsigned(ri->idata) >= MAXITEMS)
4016 {
4017 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4018 ret = -10000;
4019 break;
4020 }
4021 ret=(itemsbuf[ri->idata].magiccosttimer[1])*10000;
4022 break;
4023 // Note: never used?
4024 case IDATAUSEMVT:
4025 {
4026 if(unsigned(ri->idata) >= MAXITEMS)
4027 {
4028 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4029 ret = -10000;
4030 break;
4031 }
4032 int32_t a = vbound((ri->d[rINDEX] / 10000),0,(ITEM_MOVEMENT_PATTERNS-1));
4033 ret=(itemsbuf[ri->idata].weap_pattern[a])*10000;
4034 }
4035 break;
4036
4037 case IDATADURATION:
4038 if(unsigned(ri->idata) >= MAXITEMS)
4039 {
4040 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4041 ret = -10000;
4042 break;
4043 }
4044 ret=(itemsbuf[ri->idata].weapduration)*10000;
4045 break;
4046
4047 case IDATADUPLICATES:
4048 if(unsigned(ri->idata) >= MAXITEMS)
4049 {
4050 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4051 ret = -10000;
4052 break;
4053 }
4054 ret=(itemsbuf[ri->idata].duplicates)*10000;
4055 break;
4056 case IDATADRAWLAYER:
4057 if(unsigned(ri->idata) >= MAXITEMS)
4058 {
4059 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4060 ret = -10000;
4061 break;
4062 }
4063 ret=(itemsbuf[ri->idata].drawlayer)*10000;
4064 break;
4065 case IDATACOLLECTFLAGS:
4066 if(unsigned(ri->idata) >= MAXITEMS)
4067 {
4068 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4069 ret = 0;
4070 break;
4071 }
4072 ret=(itemsbuf[ri->idata].collectflags)*10000;
4073 break;
4074 case IDATAWEAPONSCRIPT:
4075 if(unsigned(ri->idata) >= MAXITEMS)
4076 {
4077 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4078 ret = -10000;
4079 break;
4080 }
4081 ret=(itemsbuf[ri->idata].weaponscript)*10000;
4082 break;
4083 case IDATAWEAPHXOFS:
4084 if(unsigned(ri->idata) >= MAXITEMS)
4085 {
4086 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4087 ret = -10000;
4088 break;
4089 }
4090 ret=(itemsbuf[ri->idata].weap_hxofs)*10000;
4091 break;
4092 case IDATAWEAPHYOFS:
4093 if(unsigned(ri->idata) >= MAXITEMS)
4094 {
4095 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4096 ret = -10000;
4097 break;
4098 }
4099 ret=(itemsbuf[ri->idata].weap_hyofs)*10000;
4100 break;
4101 case IDATAWEAPHXSZ:
4102 if(unsigned(ri->idata) >= MAXITEMS)
4103 {
4104 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4105 ret = -10000;
4106 break;
4107 }
4108 ret=(itemsbuf[ri->idata].weap_hxsz)*10000;
4109 break;
4110 case IDATAWEAPHYSZ:
4111 if(unsigned(ri->idata) >= MAXITEMS)
4112 {
4113 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4114 ret = -10000;
4115 break;
4116 }
4117 ret=(itemsbuf[ri->idata].weap_hysz)*10000;
4118 break;
4119 case IDATAWEAPHZSZ:
4120 if(unsigned(ri->idata) >= MAXITEMS)
4121 {
4122 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4123 ret = -10000;
4124 break;
4125 }
4126 ret=(itemsbuf[ri->idata].weap_hzsz)*10000;
4127 break;
4128 case IDATAWEAPXOFS:
4129 if(unsigned(ri->idata) >= MAXITEMS)
4130 {
4131 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4132 ret = -10000;
4133 break;
4134 }
4135 ret=(itemsbuf[ri->idata].weap_xofs)*10000;
4136 break;
4137 case IDATAWEAPYOFS:
4138 if(unsigned(ri->idata) >= MAXITEMS)
4139 {
4140 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4141 ret = -10000;
4142 break;
4143 }
4144 ret=(itemsbuf[ri->idata].weap_yofs)*10000;
4145 break;
4146 case IDATAHXOFS:
4147 if(unsigned(ri->idata) >= MAXITEMS)
4148 {
4149 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4150 ret = -10000;
4151 break;
4152 }
4153 ret=(itemsbuf[ri->idata].hxofs)*10000;
4154 break;
4155 case IDATAHYOFS:
4156 if(unsigned(ri->idata) >= MAXITEMS)
4157 {
4158 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4159 ret = -10000;
4160 break;
4161 }
4162 ret=(itemsbuf[ri->idata].hyofs)*10000;
4163 break;
4164 case IDATAHXSZ:
4165 if(unsigned(ri->idata) >= MAXITEMS)
4166 {
4167 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4168 ret = -10000;
4169 break;
4170 }
4171 ret=(itemsbuf[ri->idata].hxsz)*10000;
4172 break;
4173 case IDATAHYSZ:
4174 if(unsigned(ri->idata) >= MAXITEMS)
4175 {
4176 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4177 ret = -10000;
4178 break;
4179 }
4180 ret=(itemsbuf[ri->idata].hysz)*10000;
4181 break;
4182 case IDATAHZSZ:
4183 if(unsigned(ri->idata) >= MAXITEMS)
4184 {
4185 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4186 ret = -10000;
4187 break;
4188 }
4189 ret=(itemsbuf[ri->idata].hzsz)*10000;
4190 break;
4191 case IDATADXOFS:
4192 if(unsigned(ri->idata) >= MAXITEMS)
4193 {
4194 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4195 ret = -10000;
4196 break;
4197 }
4198 ret=(itemsbuf[ri->idata].xofs)*10000;
4199 break;
4200 case IDATADYOFS:
4201 if(unsigned(ri->idata) >= MAXITEMS)
4202 {
4203 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4204 ret = -10000;
4205 break;
4206 }
4207 ret=(itemsbuf[ri->idata].yofs)*10000;
4208 break;
4209 case IDATATILEW:
4210 if(unsigned(ri->idata) >= MAXITEMS)
4211 {
4212 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4213 ret = -10000;
4214 break;
4215 }
4216 ret=(itemsbuf[ri->idata].tilew)*10000;
4217 break;
4218 case IDATATILEH:
4219
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
53 if(unsigned(ri->idata) >= MAXITEMS)
4220 {
4221 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4222 ret = -10000;
4223 break;
4224 }
4225 53 ret=(itemsbuf[ri->idata].tileh)*10000;
4226 53 break;
4227 case IDATAPICKUP:
4228 if(unsigned(ri->idata) >= MAXITEMS)
4229 {
4230 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4231 ret = -10000;
4232 break;
4233 }
4234 ret=(itemsbuf[ri->idata].pickup)*10000;
4235 break;
4236 case IDATAOVERRIDEFL:
4237 if(unsigned(ri->idata) >= MAXITEMS)
4238 {
4239 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4240 ret = 0;
4241 break;
4242 }
4243 ret=(itemsbuf[ri->idata].overrideFLAGS)*10000;
4244 break;
4245
4246 case IDATATILEWWEAP:
4247 if(unsigned(ri->idata) >= MAXITEMS)
4248 {
4249 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4250 ret = -10000;
4251 break;
4252 }
4253 ret=(itemsbuf[ri->idata].weap_tilew)*10000;
4254 break;
4255 case IDATATILEHWEAP:
4256 if(unsigned(ri->idata) >= MAXITEMS)
4257 {
4258 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4259 ret = -10000;
4260 break;
4261 }
4262 ret=(itemsbuf[ri->idata].weap_tileh)*10000;
4263 break;
4264 case IDATAOVERRIDEFLWEAP:
4265 if(unsigned(ri->idata) >= MAXITEMS)
4266 {
4267 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4268 ret = 0;
4269 break;
4270 }
4271 ret=(itemsbuf[ri->idata].weapoverrideFLAGS)*10000;
4272 break;
4273
4274 case IDATAFAMILY:
4275
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5960535 times.
5960535 if(unsigned(ri->idata) >= MAXITEMS)
4276 {
4277 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4278 ret = -10000;
4279 break;
4280 }
4281 5960535 ret=(itemsbuf[ri->idata].family)*10000;
4282 5960535 break;
4283
4284 case IDATALEVEL:
4285
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16858 times.
16858 if(unsigned(ri->idata) >= MAXITEMS)
4286 {
4287 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4288 ret = -10000;
4289 break;
4290 }
4291 16858 ret=(itemsbuf[ri->idata].fam_type)*10000;
4292 16858 break;
4293
4294 case IDATAKEEP:
4295 3 ret = item_flag(item_gamedata);
4296 3 break;
4297
4298 case IDATAAMOUNT:
4299 {
4300 if(unsigned(ri->idata) >= MAXITEMS)
4301 {
4302 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4303 ret = -10000;
4304 break;
4305 }
4306 int32_t v = itemsbuf[ri->idata].amount;
4307 ret = ((v&0x4000)?-1:1)*(v & 0x3FFF)*10000;
4308 break;
4309 }
4310 case IDATAGRADUAL:
4311 {
4312 if(unsigned(ri->idata) >= MAXITEMS)
4313 {
4314 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4315 ret = -10000;
4316 break;
4317 }
4318 ret = (itemsbuf[ri->idata].amount&0x8000) ? 10000 : 0;
4319 break;
4320 }
4321 case IDATACONSTSCRIPT:
4322 ret = item_flag(item_passive_script);
4323 break;
4324 case IDATASSWIMDISABLED:
4325 ret = item_flag(item_sideswim_disabled);
4326 break;
4327 case IDATABUNNYABLE:
4328 ret = item_flag(item_bunny_enabled);
4329 break;
4330 case IDATAJINXIMMUNE:
4331 ret = item_flag(item_jinx_immune);
4332 break;
4333 case IDATAJINXSWAP:
4334 ret = item_flag(item_flip_jinx);
4335 break;
4336 case IDATAUSEBURNSPR:
4337 ret = item_flag(item_burning_sprites);
4338 break;
4339
4340 case IDATASETMAX:
4341 if(unsigned(ri->idata) >= MAXITEMS)
4342 {
4343 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4344 ret = -10000;
4345 break;
4346 }
4347 ret=(itemsbuf[ri->idata].setmax)*10000;
4348 break;
4349
4350 case IDATAMAX:
4351 if(unsigned(ri->idata) >= MAXITEMS)
4352 {
4353 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4354 ret = -10000;
4355 break;
4356 }
4357 ret=(itemsbuf[ri->idata].max)*10000;
4358 break;
4359
4360 case IDATACOUNTER:
4361 if(unsigned(ri->idata) >= MAXITEMS)
4362 {
4363 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4364 ret = -10000;
4365 break;
4366 }
4367 ret=(itemsbuf[ri->idata].count)*10000;
4368 break;
4369
4370 case IDATAPSOUND:
4371 if(unsigned(ri->idata) >= MAXITEMS)
4372 {
4373 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4374 ret = -10000;
4375 break;
4376 }
4377 ret=(itemsbuf[ri->idata].playsound)*10000;
4378 break;
4379 case IDATAUSESOUND:
4380 if(unsigned(ri->idata) >= MAXITEMS)
4381 {
4382 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4383 ret = -10000;
4384 break;
4385 }
4386 ret=(itemsbuf[ri->idata].usesound)*10000;
4387 break;
4388
4389 case IDATAUSESOUND2:
4390 if(unsigned(ri->idata) >= MAXITEMS)
4391 {
4392 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4393 ret = -10000;
4394 break;
4395 }
4396 ret=(itemsbuf[ri->idata].usesound2)*10000;
4397 break;
4398
4399 case IDATAPOWER:
4400
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1994 times.
1994 if(unsigned(ri->idata) >= MAXITEMS)
4401 {
4402 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4403 ret = -10000;
4404 break;
4405 }
4406 1994 ret=(itemsbuf[ri->idata].power)*10000;
4407 1994 break;
4408
4409 //Get the ID of an item.
4410 case IDATAID:
4411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1914 times.
1914 if(unsigned(ri->idata) >= MAXITEMS)
4412 {
4413 //Don't error here //scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4414 ret = -10000;
4415 break;
4416 }
4417 1914 ret=ri->idata*10000;
4418 1914 break;
4419
4420 //Get the script assigned to an item (active)
4421 case IDATASCRIPT:
4422 if(unsigned(ri->idata) >= MAXITEMS)
4423 {
4424 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4425 ret = -10000;
4426 break;
4427 }
4428 ret=(itemsbuf[ri->idata].script)*10000;
4429 break;
4430 case IDATASPRSCRIPT:
4431 if(unsigned(ri->idata) >= MAXITEMS)
4432 {
4433 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4434 ret = -10000;
4435 break;
4436 }
4437 ret=(itemsbuf[ri->idata].sprite_script)*10000;
4438 break;
4439 //Hero TIle modifier
4440 case IDATALTM:
4441 if(unsigned(ri->idata) >= MAXITEMS)
4442 {
4443 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4444 ret = 0;
4445 break;
4446 }
4447 ret=(itemsbuf[ri->idata].ltm)*10000;
4448 break;
4449 //Pickup script
4450 case IDATAPSCRIPT:
4451 if(unsigned(ri->idata) >= MAXITEMS)
4452 {
4453 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4454 ret = -10000;
4455 break;
4456 }
4457 ret=(itemsbuf[ri->idata].collect_script)*10000;
4458 break;
4459 //Pickup string
4460 case IDATAPSTRING:
4461 if(unsigned(ri->idata) >= MAXITEMS)
4462 {
4463 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4464 ret = -10000;
4465 break;
4466 }
4467 ret=(itemsbuf[ri->idata].pstring)*10000;
4468 break;
4469 case IDATAPFLAGS:
4470 if(unsigned(ri->idata) >= MAXITEMS)
4471 {
4472 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4473 ret = 0;
4474 break;
4475 }
4476 ret = (itemsbuf[ri->idata].pickup_string_flags)*10000;
4477 break;
4478 case IDATAPICKUPLITEMS:
4479 if(unsigned(ri->idata) >= MAXITEMS)
4480 {
4481 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4482 ret = 0;
4483 break;
4484 }
4485 ret = (itemsbuf[ri->idata].pickup_litems)*10000;
4486 break;
4487 case IDATAPICKUPLITEMLEVEL:
4488 if(unsigned(ri->idata) >= MAXITEMS)
4489 {
4490 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4491 ret = 0;
4492 break;
4493 }
4494 ret = (itemsbuf[ri->idata].pickup_litem_level)*10000;
4495 break;
4496 //Magic cost
4497 case IDATAMAGCOST:
4498 if(unsigned(ri->idata) >= MAXITEMS)
4499 {
4500 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4501 ret = -10000;
4502 break;
4503 }
4504 ret=(itemsbuf[ri->idata].cost_amount[0])*10000;
4505 break;
4506 case IDATACOST2:
4507 if(unsigned(ri->idata) >= MAXITEMS)
4508 {
4509 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4510 ret = -10000;
4511 break;
4512 }
4513 ret=(itemsbuf[ri->idata].cost_amount[1])*10000;
4514 break;
4515 //cost counter ref
4516 case IDATACOSTCOUNTER:
4517 if(unsigned(ri->idata) >= MAXITEMS)
4518 {
4519 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4520 ret = -10000;
4521 break;
4522 }
4523 ret=(itemsbuf[ri->idata].cost_counter[0])*10000;
4524 break;
4525 case IDATACOSTCOUNTER2:
4526 if(unsigned(ri->idata) >= MAXITEMS)
4527 {
4528 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4529 ret = -10000;
4530 break;
4531 }
4532 ret=(itemsbuf[ri->idata].cost_counter[1])*10000;
4533 break;
4534 //Min Hearts to Pick Up
4535 case IDATAMINHEARTS:
4536 if(unsigned(ri->idata) >= MAXITEMS)
4537 {
4538 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4539 ret = -10000;
4540 break;
4541 }
4542 ret=(itemsbuf[ri->idata].pickup_hearts)*10000;
4543 break;
4544 //Tile used by the item
4545 case IDATATILE:
4546
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55670 times.
55670 if(unsigned(ri->idata) >= MAXITEMS)
4547 {
4548 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4549 ret = -10000;
4550 break;
4551 }
4552 55670 ret=(itemsbuf[ri->idata].tile)*10000;
4553 55670 break;
4554 //itemdata->Flash
4555 case IDATAMISC:
4556 if(unsigned(ri->idata) >= MAXITEMS)
4557 {
4558 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4559 ret = -10000;
4560 break;
4561 }
4562 ret=(itemsbuf[ri->idata].misc_flags)*10000;
4563 break;
4564 //->CSet
4565 case IDATACSET:
4566
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55645 times.
55645 if(unsigned(ri->idata) >= MAXITEMS)
4567 {
4568 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4569 ret = -10000;
4570 break;
4571 }
4572
4573 55645 ret = (itemsbuf[ri->idata].csets&15)*10000;
4574
4575 // If we find quests that broke, use this code.
4576 // if (QHeader.compareVer(2, 55, 9) >= 0)
4577 // ret = (itemsbuf[ri->idata].csets&15)*10000;
4578 // else
4579 // ret = itemsbuf[ri->idata].csets*10000;
4580 55645 break;
4581 case IDATAFLASHCSET:
4582 if(unsigned(ri->idata) >= MAXITEMS)
4583 {
4584 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4585 ret = -10000;
4586 break;
4587 }
4588 ret=(itemsbuf[ri->idata].csets>>4)*10000;
4589 break;
4590 //->A.Frames
4591 case IDATAFRAMES:
4592
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 63041 times.
63041 if(unsigned(ri->idata) >= MAXITEMS)
4593 {
4594 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4595 ret = -10000;
4596 break;
4597 }
4598 63041 ret=(itemsbuf[ri->idata].frames)*10000;
4599 63041 break;
4600 /*
4601 case IDATAFRAME:
4602 ret=(itemsbuf[ri->idata].frame)*10000;
4603 break;
4604 */
4605 //->A.Speed
4606 case IDATAASPEED:
4607
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 142873 times.
142873 if(unsigned(ri->idata) >= MAXITEMS)
4608 {
4609 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4610 ret = -10000;
4611 break;
4612 }
4613 142873 ret=(itemsbuf[ri->idata].speed)*10000;
4614 142873 break;
4615 //->Delay
4616 case IDATADELAY:
4617
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 74538 times.
74538 if(unsigned(ri->idata) >= MAXITEMS)
4618 {
4619 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
4620 ret = -10000;
4621 break;
4622 }
4623 74538 ret=(itemsbuf[ri->idata].delay)*10000;
4624 74538 break;
4625 // teo of this item upgrades
4626 case IDATACOMBINE:
4627 ret = item_flag(item_combine);
4628 break;
4629 //Use item, and get the lower level one
4630 case IDATADOWNGRADE:
4631 ret = item_flag(item_downgrade);
4632 break;
4633 //Only validate the cost, don't charge it
4634 case IDATAVALIDATE:
4635 ret = item_flag(item_validate_only);
4636 break;
4637 case IDATAVALIDATE2:
4638 ret = item_flag(item_validate_only_2);
4639 break;
4640 //->Keep Old
4641 case IDATAKEEPOLD:
4642 ret = item_flag(item_keep_old);
4643 break;
4644 //Use rupees instead of magic
4645 case IDATARUPEECOST:
4646 ret = item_flag(item_rupee_magic);
4647 break;
4648 //Can be eaten
4649 case IDATAEDIBLE:
4650 ret = item_flag(item_edible);
4651 break;
4652 //currently unused
4653 case IDATAFLAGUNUSED:
4654 ret = item_flag(item_unused);
4655 break;
4656 //Gain lower level items when collected
4657 case IDATAGAINLOWER:
4658 ret = item_flag(item_gain_old);
4659 break;
4660
4661 ///----------------------------------------------------------------------------------------------------//
4662 //LWeapon Variables
4663 case LWPNSPECIAL:
4664 if(0!=(s=checkLWpn(ri->lwpn)))
4665 ret=((int32_t)((weapon*)(s))->specialinfo)*10000;
4666
4667
4668 break;
4669
4670 case LWPNSCALE:
4671 if ( get_qr(qr_OLDSPRITEDRAWS) )
4672 {
4673 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
4674 ret = -1; break;
4675 }
4676 if(0!=(s=checkLWpn(ri->lwpn)))
4677 ret=((int32_t)((weapon*)(s))->scale)*100.0;
4678
4679 break;
4680
4681 case LWPNX:
4682
2/2
✓ Branch 0 taken 15492 times.
✓ Branch 1 taken 939265 times.
954757 if(0!=(s=checkLWpn(ri->lwpn)))
4683 {
4684
2/2
✓ Branch 0 taken 350528 times.
✓ Branch 1 taken 588737 times.
939265 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
4685 {
4686 350528 ret=(((weapon*)(s))->x).getZLong();
4687 350528 }
4688 else
4689 588737 ret=((int32_t)((weapon*)(s))->x)*10000;
4690 939265 }
4691
4692 954757 break;
4693
4694 case SPRITEMAXLWPN:
4695 {
4696 //No bounds check, as this is a universal function and works from NULL pointers!
4697 ret = Lwpns.getMax() * 10000;
4698 break;
4699 }
4700
4701 case LWPNY:
4702
2/2
✓ Branch 0 taken 15492 times.
✓ Branch 1 taken 934658 times.
950150 if(0!=(s=checkLWpn(ri->lwpn)))
4703 {
4704
2/2
✓ Branch 0 taken 350395 times.
✓ Branch 1 taken 584263 times.
934658 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
4705 {
4706 350395 ret=(((weapon*)(s))->y).getZLong();
4707 350395 }
4708 else
4709 584263 ret=((int32_t)((weapon*)(s))->y)*10000;
4710 934658 }
4711 950150 break;
4712
4713 case LWPNZ:
4714
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 109736 times.
109736 if(0!=(s=checkLWpn(ri->lwpn)))
4715 {
4716
2/2
✓ Branch 0 taken 53984 times.
✓ Branch 1 taken 55752 times.
109736 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
4717 {
4718 53984 ret=(((weapon*)(s))->z).getZLong();
4719 53984 }
4720 else
4721 55752 ret=((int32_t)((weapon*)(s))->z)*10000;
4722 109736 }
4723
4724 109736 break;
4725
4726 case LWPNJUMP:
4727
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
4728 {
4729 6 ret = ((weapon*)(s))->fall.getZLong() / -100;
4730
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (get_qr(qr_SPRITE_JUMP_IS_TRUNCATED)) ret = trunc(ret / 10000) * 10000;
4731 6 }
4732
4733 6 break;
4734
4735 case LWPNFAKEJUMP:
4736 if(0!=(s=checkLWpn(ri->lwpn)))
4737 {
4738 ret = ((weapon*)(s))->fakefall.getZLong() / -100;
4739 if (get_qr(qr_SPRITE_JUMP_IS_TRUNCATED)) ret = trunc(ret / 10000) * 10000;
4740 }
4741
4742 break;
4743
4744 case LWPNDIR:
4745
1/2
✓ Branch 0 taken 80933 times.
✗ Branch 1 not taken.
80933 if(0!=(s=checkLWpn(ri->lwpn)))
4746 80933 ret=((weapon*)(s))->dir*10000;
4747
4748 80933 break;
4749
4750 case LWPNGRAVITY:
4751 if(0!=(s=checkLWpn(ri->lwpn)))
4752 ret= (((weapon*)(s))->moveflags & move_obeys_grav) ? 10000 : 0;
4753
4754 break;
4755
4756 case LWPNSTEP:
4757
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5388 times.
5388 if(0!=(s=checkLWpn(ri->lwpn)))
4758 {
4759
3/4
✓ Branch 0 taken 1140 times.
✓ Branch 1 taken 4248 times.
✓ Branch 2 taken 1140 times.
✗ Branch 3 not taken.
5388 if ( get_qr(qr_STEP_IS_FLOAT) || replay_is_active() )
4760 {
4761 5388 ret=((weapon*)s)->step.getZLong() * 100;
4762 5388 }
4763 //old, buggy code replication, round two: Go! -Z
4764 //else ret = ( ( ( ((weapon*)s)->step ) * 100.0 ).getZLong() );
4765
4766 //else
4767 //{
4768 //old, buggy code replication, round THREE: Go! -Z
4769 // double tmp = ( ((weapon*)s)->step.getFloat() ) * 1000000.0;
4770 // ret = (int32_t)tmp;
4771 //}
4772
4773 //old, buggy code replication, round FOUR: Go! -Z
4774 else ret = (int32_t)((float)((weapon*)s)->step * 1000000.0);
4775 5388 }
4776 5388 break;
4777
4778 case LWPNANGLE:
4779
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 416 times.
416 if(0!=(s=checkLWpn(ri->lwpn)))
4780 416 ret=(int32_t)(((weapon*)(s))->angle*10000);
4781
4782 416 break;
4783
4784 case LWPNDEGANGLE:
4785 if(0!=(s=checkLWpn(ri->lwpn)))
4786 {
4787 ret=(int32_t)(((weapon*)(s))->angle*(180.0 / PI)*10000);
4788 }
4789
4790 break;
4791
4792 case LWPNVX:
4793
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 246 times.
246 if(0!=(s=checkLWpn(ri->lwpn)))
4794 {
4795
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 246 times.
246 if (((weapon*)(s))->angular)
4796 ret = int32_t(zc::math::Cos(((weapon*)s)->angle)*10000.0*((weapon*)s)->step);
4797 else
4798 {
4799
4/7
✓ Branch 0 taken 246 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 246 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 122 times.
✓ Branch 6 taken 124 times.
246 switch(NORMAL_DIR(((weapon*)(s))->dir))
4800 {
4801 case l_up:
4802 case l_down:
4803 case left:
4804 ret = int32_t(-10000.0*((weapon*)s)->step);
4805 break;
4806
4807 case r_down:
4808 case r_up:
4809 case right:
4810 122 ret = int32_t(10000.0*((weapon*)s)->step);
4811 122 break;
4812
4813 default:
4814 124 ret = 0;
4815 124 break;
4816 }
4817 }
4818 246 }
4819
4820 246 break;
4821
4822 case LWPNVY:
4823 if(0!=(s=checkLWpn(ri->lwpn)))
4824 {
4825 if (((weapon*)(s))->angular)
4826 ret = int32_t(zc::math::Sin(((weapon*)s)->angle)*10000.0*((weapon*)s)->step);
4827 else
4828 {
4829 switch(NORMAL_DIR(((weapon*)(s))->dir))
4830 {
4831 case l_up:
4832 case r_up:
4833 case up:
4834 ret = int32_t(-10000.0*((weapon*)s)->step);
4835 break;
4836 case l_down:
4837 case r_down:
4838 case down:
4839 ret = int32_t(10000.0*((weapon*)s)->step);
4840 break;
4841
4842 default:
4843 ret = 0;
4844 break;
4845 }
4846 }
4847 }
4848
4849 break;
4850
4851 case LWPNANGULAR:
4852
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
4853 6 ret=((weapon*)(s))->angular*10000;
4854
4855 6 break;
4856
4857 case LWPNAUTOROTATE:
4858 if(0!=(s=checkLWpn(ri->lwpn)))
4859 ret=((weapon*)(s))->autorotate*10000;
4860
4861 break;
4862
4863 case LWPNBEHIND:
4864 if(0!=(s=checkLWpn(ri->lwpn)))
4865 ret=((weapon*)(s))->behind*10000;
4866
4867 break;
4868
4869 case LWPNDRAWTYPE:
4870
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
4871 6 ret=((weapon*)(s))->drawstyle*10000;
4872
4873 6 break;
4874
4875 case LWPNPOWER:
4876
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 103895 times.
103896 if(0!=(s=checkLWpn(ri->lwpn)))
4877 103895 ret=((weapon*)(s))->power*10000;
4878
4879 103896 break;
4880 /*
4881 case LWPNRANGE:
4882 if(0!=(s=checkLWpn(ri->lwpn)))
4883 ret=((weapon*)(s))->scriptrange*10000;
4884
4885 break;
4886 */
4887 case LWPNDEAD:
4888
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7611 times.
7611 if(0!=(s=checkLWpn(ri->lwpn)))
4889 7611 ret=((weapon*)(s))->dead*10000;
4890
4891 7611 break;
4892
4893 case LWPNID:
4894
2/2
✓ Branch 0 taken 16620 times.
✓ Branch 1 taken 4092488 times.
4109108 if(0!=(s=checkLWpn(ri->lwpn)))
4895 4092488 ret=((weapon*)(s))->id*10000;
4896
4897 4109108 break;
4898
4899 case LWPNTILE:
4900
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53697 times.
53697 if(0!=(s=checkLWpn(ri->lwpn)))
4901 53697 ret=((weapon*)(s))->tile*10000;
4902
4903 53697 break;
4904
4905 case LWPNSCRIPTTILE:
4906
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
586 if(0!=(s=checkLWpn(ri->lwpn)))
4907 586 ret=((weapon*)(s))->scripttile*10000;
4908
4909 586 break;
4910
4911 case LWPNSCRIPTFLIP:
4912 if(0!=(s=checkLWpn(ri->lwpn)))
4913 ret=((weapon*)(s))->scriptflip*10000;
4914
4915 break;
4916
4917 case LWPNCSET:
4918
1/2
✓ Branch 0 taken 53381 times.
✗ Branch 1 not taken.
53381 if(0!=(s=checkLWpn(ri->lwpn)))
4919 53381 ret=((weapon*)(s))->cs*10000;
4920
4921 53381 break;
4922
4923 case LWPNFLASHCSET:
4924
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 220 times.
220 if(0!=(s=checkLWpn(ri->lwpn)))
4925 220 ret=(((weapon*)(s))->o_cset>>4)*10000;
4926
4927 220 break;
4928
4929 case LWPNFRAMES:
4930
1/2
✓ Branch 0 taken 4362 times.
✗ Branch 1 not taken.
4362 if(0!=(s=checkLWpn(ri->lwpn)))
4931 4362 ret=((weapon*)(s))->frames*10000;
4932
4933 4362 break;
4934
4935 case LWPNFRAME:
4936
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
4937 6 ret=((weapon*)(s))->aframe*10000;
4938
4939 6 break;
4940
4941 case LWPNASPEED:
4942
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4362 times.
4362 if(0!=(s=checkLWpn(ri->lwpn)))
4943 4362 ret=((weapon*)(s))->o_speed*10000;
4944
4945 4362 break;
4946
4947 case LWPNFLASH:
4948
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
4949 6 ret=((weapon*)(s))->flash*10000;
4950
4951 6 break;
4952
4953 case LWPNFLIP:
4954 if(0!=(s=checkLWpn(ri->lwpn)))
4955 ret=((weapon*)(s))->flip*10000;
4956
4957 break;
4958
4959 case LWPNCOUNT:
4960 1950927 ret=Lwpns.Count()*10000;
4961 1950927 break;
4962
4963 case LWPNEXTEND:
4964
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
4965 6 ret=((weapon*)(s))->extend*10000;
4966
4967 6 break;
4968
4969 case LWPNOTILE:
4970
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 835937 times.
835937 if(0!=(s=checkLWpn(ri->lwpn)))
4971 835937 ret=((weapon*)(s))->o_tile*10000;
4972
4973 835937 break;
4974
4975 case LWPNOCSET:
4976
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23909 times.
23909 if(0!=(s=checkLWpn(ri->lwpn)))
4977 23909 ret=(((weapon*)(s))->o_cset&15)*10000;
4978
4979 23909 break;
4980
4981 case LWPNHXOFS:
4982
2/2
✓ Branch 0 taken 284226 times.
✓ Branch 1 taken 15492 times.
299718 if(0!=(s=checkLWpn(ri->lwpn)))
4983 284226 ret=(((weapon*)(s))->hxofs)*10000;
4984
4985 299718 break;
4986
4987 case LWPNHYOFS:
4988
2/2
✓ Branch 0 taken 281478 times.
✓ Branch 1 taken 15492 times.
296970 if(0!=(s=checkLWpn(ri->lwpn)))
4989 281478 ret=(((weapon*)(s))->hyofs)*10000;
4990
4991 296970 break;
4992
4993 case LWPNXOFS:
4994
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10231 times.
10231 if(0!=(s=checkLWpn(ri->lwpn)))
4995 10231 ret=((int32_t)(((weapon*)(s))->xofs))*10000;
4996
4997 10231 break;
4998
4999 case LWPNYOFS:
5000
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11477 times.
11477 if(0!=(s=checkLWpn(ri->lwpn)))
5001
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11477 times.
11477 ret=((int32_t)(((weapon*)(s))->yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset)))*10000;
5002
5003 11477 break;
5004
5005 case LWPNSHADOWXOFS:
5006 if(0!=(s=checkLWpn(ri->lwpn)))
5007 ret=((int32_t)(((weapon*)(s))->shadowxofs))*10000;
5008
5009 break;
5010
5011 case LWPNSHADOWYOFS:
5012 if(0!=(s=checkLWpn(ri->lwpn)))
5013 ret=((int32_t)(((weapon*)(s))->shadowyofs))*10000;
5014
5015 break;
5016
5017 case LWPNTOTALDYOFFS:
5018 if(0!=(s=checkLWpn(ri->lwpn)))
5019 ret = ((int32_t)(((weapon*)(s))->yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset))
5020 + ((((weapon*)(s))->switch_hooked && Hero.switchhookstyle == swRISE)
5021 ? -(8-(abs(Hero.switchhookclk-32)/4)) : 0)) * 10000;
5022 break;
5023
5024 case LWPNZOFS:
5025
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(0!=(s=checkLWpn(ri->lwpn)))
5026 6 ret=((int32_t)(((weapon*)(s))->zofs))*10000;
5027
5028 6 break;
5029
5030 case LWPNHXSZ:
5031
2/2
✓ Branch 0 taken 15492 times.
✓ Branch 1 taken 267550 times.
283042 if(0!=(s=checkLWpn(ri->lwpn)))
5032 267550 ret=(((weapon*)(s))->hit_width)*10000;
5033
5034 283042 break;
5035
5036 case LWPNHYSZ:
5037
2/2
✓ Branch 0 taken 15492 times.
✓ Branch 1 taken 269504 times.
284996 if(0!=(s=checkLWpn(ri->lwpn)))
5038 269504 ret=(((weapon*)(s))->hit_height)*10000;
5039
5040 284996 break;
5041
5042 case LWPNHZSZ:
5043
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36540 times.
36540 if(0!=(s=checkLWpn(ri->lwpn)))
5044 36540 ret=(((weapon*)(s))->hzsz)*10000;
5045
5046 36540 break;
5047
5048 case LWPNTXSZ:
5049
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32019 times.
32019 if(0!=(s=checkLWpn(ri->lwpn)))
5050 32019 ret=(((weapon*)(s))->txsz)*10000;
5051
5052 32019 break;
5053
5054 case LWPNTYSZ:
5055
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32019 times.
32019 if(0!=(s=checkLWpn(ri->lwpn)))
5056 32019 ret=(((weapon*)(s))->tysz)*10000;
5057
5058 32019 break;
5059
5060 case LWPNCOLLDET:
5061
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5455 times.
5455 if(0!=(s=checkLWpn(ri->lwpn)))
5062 5455 ret=(((weapon*)(s))->scriptcoldet)*10000;
5063
5064 5455 break;
5065
5066 case LWPNENGINEANIMATE:
5067 if(0!=(s=checkLWpn(ri->lwpn)))
5068 ret=(((weapon*)(s))->do_animation)*10000;
5069
5070 break;
5071
5072 case LWPNPARENT:
5073 if(0!=(s=checkLWpn(ri->lwpn)))
5074 ret=(((weapon*)(s))->parentitem)*10000;
5075
5076 break;
5077
5078 case LWPNLEVEL:
5079 if(0!=(s=checkLWpn(ri->lwpn)))
5080 ret=(((weapon*)(s))->type)*10000;
5081
5082 break;
5083
5084 case LWPNSCRIPT:
5085
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(0!=(s=checkLWpn(ri->lwpn)))
5086 3 ret=(((weapon*)(s))->weaponscript)*10000;
5087
5088 3 break;
5089
5090 case LWPNUSEWEAPON:
5091
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60075 times.
60075 if(0!=(s=checkLWpn(ri->lwpn)))
5092 60075 ret=(((weapon*)(s))->useweapon)*10000;
5093
5094 60075 break;
5095
5096 case LWPNUSEDEFENCE:
5097 if(0!=(s=checkLWpn(ri->lwpn)))
5098 ret=(((weapon*)(s))->usedefense)*10000;
5099
5100 break;
5101
5102 case LWEAPONSCRIPTUID:
5103 if(0!=(s=checkLWpn(ri->lwpn)))
5104 ret=(((weapon*)(s))->getUID());
5105
5106 break;
5107
5108 case LWPNROTATION:
5109 if ( get_qr(qr_OLDSPRITEDRAWS) )
5110 {
5111 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
5112 ret = -1; break;
5113 }
5114 if(0!=(s=checkLWpn(ri->lwpn)))
5115 ret=((weapon*)(s))->rotation*10000;
5116
5117 break;
5118
5119 case LWPNFALLCLK:
5120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1552 times.
1552 if(0!=(s=checkLWpn(ri->lwpn)))
5121 {
5122 1552 ret = ((weapon*)(s))->fallclk * 10000;
5123 1552 }
5124 1552 break;
5125
5126 case LWPNFALLCMB:
5127 if(0!=(s=checkLWpn(ri->lwpn)))
5128 {
5129 ret = ((weapon*)(s))->fallCombo * 10000;
5130 }
5131 break;
5132
5133 case LWPNDROWNCLK:
5134 if(0!=(s=checkLWpn(ri->lwpn)))
5135 {
5136 ret = ((weapon*)(s))->drownclk * 10000;
5137 }
5138 break;
5139
5140 case LWPNDROWNCMB:
5141 if(0!=(s=checkLWpn(ri->lwpn)))
5142 {
5143 ret = ((weapon*)(s))->drownCombo * 10000;
5144 }
5145 break;
5146
5147 case LWPNFAKEZ:
5148 if(0!=(s=checkLWpn(ri->lwpn)))
5149 {
5150 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
5151 {
5152 ret=(((weapon*)(s))->fakez).getZLong();
5153 }
5154 else
5155 ret=((int32_t)((weapon*)(s))->fakez)*10000;
5156 }
5157 break;
5158
5159 case LWPNGLOWRAD:
5160
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48553 times.
48553 if(0!=(s=checkLWpn(ri->lwpn)))
5161 {
5162 48553 ret = ((weapon*)(s))->glowRad * 10000;
5163 48553 }
5164 48553 break;
5165
5166 case LWPNGLOWSHP:
5167 if(0!=(s=checkLWpn(ri->lwpn)))
5168 {
5169 ret = ((weapon*)(s))->glowShape * 10000;
5170 }
5171 break;
5172
5173 case LWPNUNBL:
5174 if(0!=(s=checkLWpn(ri->lwpn)))
5175 {
5176 ret = ((weapon*)(s))->unblockable * 10000;
5177 }
5178 break;
5179
5180 case LWPNSHADOWSPR:
5181 if(0!=(s=checkLWpn(ri->lwpn)))
5182 {
5183 ret = ((weapon*)(s))->spr_shadow * 10000;
5184 }
5185 break;
5186 case LWSWHOOKED:
5187 if(0!=(s=checkLWpn(ri->lwpn)))
5188 {
5189 ret = s->switch_hooked ? 10000 : 0;
5190 }
5191 break;
5192 case LWPNTIMEOUT:
5193 if(0!=(s=checkLWpn(ri->lwpn)))
5194 {
5195 ret = ((weapon*)(s))->weap_timeout * 10000;
5196 }
5197 break;
5198 case LWPNDEATHITEM:
5199 if(0!=(s=checkLWpn(ri->lwpn)))
5200 {
5201 ret = ((weapon*)(s))->death_spawnitem * 10000;
5202 }
5203 break;
5204 case LWPNDEATHDROPSET:
5205 if(0!=(s=checkLWpn(ri->lwpn)))
5206 {
5207 ret = ((weapon*)(s))->death_spawndropset * 10000;
5208 }
5209 break;
5210 case LWPNDEATHIPICKUP:
5211 if(0!=(s=checkLWpn(ri->lwpn)))
5212 {
5213 ret = ((weapon*)(s))->death_item_pflags * 10000;
5214 }
5215 break;
5216 case LWPNDEATHSPRITE:
5217 if(0!=(s=checkLWpn(ri->lwpn)))
5218 {
5219 ret = ((weapon*)(s))->death_sprite * 10000;
5220 }
5221 break;
5222 case LWPNDEATHSFX:
5223 if(0!=(s=checkLWpn(ri->lwpn)))
5224 {
5225 ret = ((weapon*)(s))->death_sfx * 10000;
5226 }
5227 break;
5228 case LWPNLIFTLEVEL:
5229 if(0!=(s=checkLWpn(ri->lwpn)))
5230 {
5231 ret = ((weapon*)(s))->lift_level * 10000;
5232 }
5233 break;
5234 case LWPNLIFTTIME:
5235 if(0!=(s=checkLWpn(ri->lwpn)))
5236 {
5237 ret = ((weapon*)(s))->lift_time * 10000;
5238 }
5239 break;
5240 case LWPNLIFTHEIGHT:
5241 if(0!=(s=checkLWpn(ri->lwpn)))
5242 {
5243 ret = ((weapon*)(s))->lift_height.getZLong();
5244 }
5245 break;
5246
5247 ///----------------------------------------------------------------------------------------------------//
5248 //EWeapon Variables
5249 case EWPNSCALE:
5250 if ( get_qr(qr_OLDSPRITEDRAWS) )
5251 {
5252 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
5253 ret = -1; break;
5254 }
5255 if(0!=(s=checkEWpn(ri->ewpn)))
5256 ret=((int32_t)((weapon*)(s))->scale)*100.0;
5257
5258 break;
5259
5260 case EWPNX:
5261
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4354386 times.
4354386 if(0!=(s=checkEWpn(ri->ewpn)))
5262 {
5263
2/2
✓ Branch 0 taken 219258 times.
✓ Branch 1 taken 4135128 times.
4354386 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
5264 {
5265 219258 ret=(((weapon*)(s))->x).getZLong();
5266 219258 }
5267 else
5268 4135128 ret=((int32_t)((weapon*)(s))->x)*10000;
5269 4354386 }
5270 4354386 break;
5271
5272 case SPRITEMAXEWPN:
5273 {
5274 //No bounds check, as this is a universal function and works from NULL pointers!
5275 ret = Ewpns.getMax() * 10000;
5276 break;
5277 }
5278
5279 case EWPNY:
5280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4354484 times.
4354484 if(0!=(s=checkEWpn(ri->ewpn)))
5281 {
5282
2/2
✓ Branch 0 taken 219111 times.
✓ Branch 1 taken 4135373 times.
4354484 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
5283 {
5284 219111 ret=(((weapon*)(s))->y).getZLong();
5285 219111 }
5286 else
5287 4135373 ret=((int32_t)((weapon*)(s))->y)*10000;
5288 4354484 }
5289 4354484 break;
5290
5291 case EWPNZ:
5292
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 552907 times.
552907 if(0!=(s=checkEWpn(ri->ewpn)))
5293 {
5294
2/2
✓ Branch 0 taken 1432 times.
✓ Branch 1 taken 551475 times.
552907 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
5295 {
5296 1432 ret=(((weapon*)(s))->z).getZLong();
5297 1432 }
5298 else
5299 551475 ret=((int32_t)((weapon*)(s))->z)*10000;
5300 552907 }
5301 552907 break;
5302
5303 case EWPNJUMP:
5304 if(0!=(s=checkEWpn(ri->ewpn)))
5305 {
5306 ret = ((weapon*)(s))->fall.getZLong() / -100;
5307 if (get_qr(qr_SPRITE_JUMP_IS_TRUNCATED)) ret = trunc(ret / 10000) * 10000;
5308 }
5309
5310 break;
5311
5312 case EWPNFAKEJUMP:
5313 if(0!=(s=checkEWpn(ri->ewpn)))
5314 {
5315 ret = ((weapon*)(s))->fakefall.getZLong() / -100;
5316 if (get_qr(qr_SPRITE_JUMP_IS_TRUNCATED)) ret = trunc(ret / 10000) * 10000;
5317 }
5318
5319 break;
5320
5321 case EWPNDIR:
5322
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 61563 times.
61563 if(0!=(s=checkEWpn(ri->ewpn)))
5323 61563 ret=((weapon*)(s))->dir*10000;
5324
5325 61563 break;
5326
5327 case EWPNLEVEL:
5328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2845 times.
2845 if(0!=(s=checkEWpn(ri->ewpn)))
5329 2845 ret=((weapon*)(s))->type*10000;
5330
5331 2845 break;
5332
5333 case EWPNGRAVITY:
5334 if(0!=(s=checkEWpn(ri->ewpn)))
5335 ret=((((weapon*)(s))->moveflags & move_obeys_grav) ? 10000 : 0);
5336
5337 break;
5338
5339 case EWPNSTEP:
5340
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 610345 times.
610345 if(0!=(s=checkEWpn(ri->ewpn)))
5341 {
5342
3/4
✓ Branch 0 taken 610183 times.
✓ Branch 1 taken 162 times.
✓ Branch 2 taken 610183 times.
✗ Branch 3 not taken.
610345 if ( get_qr(qr_STEP_IS_FLOAT) || replay_is_active() )
5343 {
5344 610345 ret=((weapon*)s)->step.getZLong() * 100;
5345 610345 }
5346 //old, buggy code replication, round two: Go! -Z
5347 //else ret = ( ( ( ((weapon*)s)->step ) * 100.0 ).getZLong() );
5348 //old, buggy code replication, round FOUR: Go! -Z
5349 else ret = (int32_t)((float)((weapon*)s)->step * 1000000.0);
5350 610345 }
5351 //else
5352 //{
5353 //old, buggy code replication, round THREE: Go! -Z
5354 // double tmp = ( ((weapon*)s)->step.getFloat() ) * 1000000.0;
5355 // ret = int32_t(tmp);
5356 //}
5357 610345 break;
5358
5359 case EWPNANGLE:
5360
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 718383 times.
718383 if(0!=(s=checkEWpn(ri->ewpn)))
5361 718383 ret=(int32_t)(((weapon*)(s))->angle*10000);
5362
5363 718383 break;
5364
5365 case EWPNDEGANGLE:
5366 if(0!=(s=checkEWpn(ri->ewpn)))
5367 {
5368 ret=(int32_t)(((weapon*)(s))->angle*(180.0 / PI)*10000);
5369 }
5370
5371 break;
5372
5373 case EWPNVX:
5374 if(0!=(s=checkEWpn(ri->ewpn)))
5375 {
5376 if (((weapon*)(s))->angular)
5377 ret = int32_t(zc::math::Cos(((weapon*)s)->angle)*10000.0*((weapon*)s)->step);
5378 else
5379 {
5380 switch(NORMAL_DIR(((weapon*)(s))->dir))
5381 {
5382 case l_up:
5383 case l_down:
5384 case left:
5385 ret = int32_t(-10000.0*((weapon*)s)->step);
5386 break;
5387 case r_up:
5388 case r_down:
5389 case right:
5390 ret = int32_t(10000.0*((weapon*)s)->step);
5391 break;
5392
5393 default:
5394 ret = 0;
5395 break;
5396 }
5397 }
5398 }
5399
5400 break;
5401
5402 case EWPNVY:
5403 if(0!=(s=checkEWpn(ri->ewpn)))
5404 {
5405 if (((weapon*)(s))->angular)
5406 ret = int32_t(zc::math::Sin(((weapon*)s)->angle)*10000.0*((weapon*)s)->step);
5407 else
5408 {
5409 switch(NORMAL_DIR(((weapon*)(s))->dir))
5410 {
5411 case l_up:
5412 case r_up:
5413 case up:
5414 ret = int32_t(-10000.0*((weapon*)s)->step);
5415 break;
5416 case l_down:
5417 case r_down:
5418 case down:
5419 ret = int32_t(10000.0*((weapon*)s)->step);
5420 break;
5421
5422 default:
5423 ret = 0;
5424 break;
5425 }
5426 }
5427 }
5428
5429 break;
5430
5431
5432 case EWPNANGULAR:
5433
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 136793 times.
136793 if(0!=(s=checkEWpn(ri->ewpn)))
5434 136793 ret=((weapon*)(s))->angular*10000;
5435
5436 136793 break;
5437
5438 case EWPNAUTOROTATE:
5439 if(0!=(s=checkEWpn(ri->ewpn)))
5440 ret=((weapon*)(s))->autorotate*10000;
5441
5442 break;
5443
5444 case EWPNBEHIND:
5445 if(0!=(s=checkEWpn(ri->ewpn)))
5446 ret=((weapon*)(s))->behind*10000;
5447
5448 break;
5449
5450 case EWPNDRAWTYPE:
5451
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46359 times.
46359 if(0!=(s=checkEWpn(ri->ewpn)))
5452 46359 ret=((weapon*)(s))->drawstyle*10000;
5453
5454 46359 break;
5455
5456 case EWPNPOWER:
5457
1/2
✓ Branch 0 taken 90304 times.
✗ Branch 1 not taken.
90304 if(0!=(s=checkEWpn(ri->ewpn)))
5458 90304 ret=((weapon*)(s))->power*10000;
5459
5460 90304 break;
5461
5462 case EWPNDEAD:
5463
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6052 times.
6052 if(0!=(s=checkEWpn(ri->ewpn)))
5464 6052 ret=((weapon*)(s))->dead*10000;
5465
5466 6052 break;
5467
5468 case EWPNID:
5469
2/2
✓ Branch 0 taken 72689 times.
✓ Branch 1 taken 2727389 times.
2800078 if(0!=(s=checkEWpn(ri->ewpn)))
5470 2727389 ret=((weapon*)(s))->id*10000;
5471
5472 2800078 break;
5473
5474 case EWPNTILE:
5475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 205013 times.
205013 if(0!=(s=checkEWpn(ri->ewpn)))
5476 205013 ret=((weapon*)(s))->tile*10000;
5477
5478 205013 break;
5479
5480 case EWPNSCRIPTTILE:
5481 if(0!=(s=checkEWpn(ri->ewpn)))
5482 ret=((weapon*)(s))->scripttile*10000;
5483
5484 break;
5485
5486 case EWPNSCRIPTFLIP:
5487 if(0!=(s=checkEWpn(ri->ewpn)))
5488 ret=((weapon*)(s))->scriptflip*10000;
5489
5490 break;
5491
5492 case EWPNCSET:
5493
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 65315 times.
65315 if(0!=(s=checkEWpn(ri->ewpn)))
5494 65315 ret=((weapon*)(s))->cs*10000;
5495
5496 65315 break;
5497
5498 case EWPNFLASHCSET:
5499 if(0!=(s=checkEWpn(ri->ewpn)))
5500 ret=(((weapon*)(s))->o_cset>>4)*10000;
5501
5502 break;
5503
5504 case EWPNFRAMES:
5505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 if(0!=(s=checkEWpn(ri->ewpn)))
5506 96 ret=((weapon*)(s))->frames*10000;
5507
5508 96 break;
5509
5510 case EWPNFRAME:
5511 if(0!=(s=checkEWpn(ri->ewpn)))
5512 ret=((weapon*)(s))->aframe*10000;
5513
5514 break;
5515
5516 case EWPNASPEED:
5517
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(0!=(s=checkEWpn(ri->ewpn)))
5518 96 ret=((weapon*)(s))->o_speed*10000;
5519
5520 96 break;
5521
5522 case EWPNFLASH:
5523 if(0!=(s=checkEWpn(ri->ewpn)))
5524 ret=((weapon*)(s))->flash*10000;
5525
5526 break;
5527
5528 case EWPNFLIP:
5529
1/2
✓ Branch 0 taken 12006 times.
✗ Branch 1 not taken.
12006 if(0!=(s=checkEWpn(ri->ewpn)))
5530 12006 ret=((weapon*)(s))->flip*10000;
5531
5532 12006 break;
5533
5534 case EWPNROTATION:
5535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 218 times.
218 if ( get_qr(qr_OLDSPRITEDRAWS) )
5536 {
5537 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'");
5538 break;
5539 }
5540
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 218 times.
218 if(0!=(s=checkEWpn(ri->ewpn)))
5541 218 ret=((weapon*)(s))->rotation*10000;
5542
5543 218 break;
5544
5545 case EWPNCOUNT:
5546 6012394 ret=Ewpns.Count()*10000;
5547 6012394 break;
5548
5549 case EWPNEXTEND:
5550 if(0!=(s=checkEWpn(ri->ewpn)))
5551 ret=((weapon*)(s))->extend*10000;
5552
5553 break;
5554
5555 case EWPNOTILE:
5556
1/2
✓ Branch 0 taken 10477 times.
✗ Branch 1 not taken.
10477 if(0!=(s=checkEWpn(ri->ewpn)))
5557 10477 ret=((weapon*)(s))->o_tile*10000;
5558
5559 10477 break;
5560
5561 case EWPNOCSET:
5562 if(0!=(s=checkEWpn(ri->ewpn)))
5563 ret=(((weapon*)(s))->o_cset&15)*10000;
5564
5565 break;
5566
5567 case EWPNHXOFS:
5568
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 157773 times.
157773 if(0!=(s=checkEWpn(ri->ewpn)))
5569 157773 ret=(((weapon*)(s))->hxofs)*10000;
5570
5571 157773 break;
5572
5573 case EWPNHYOFS:
5574
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 157773 times.
157773 if(0!=(s=checkEWpn(ri->ewpn)))
5575 157773 ret=(((weapon*)(s))->hyofs)*10000;
5576
5577 157773 break;
5578
5579 case EWPNXOFS:
5580
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48464 times.
48464 if(0!=(s=checkEWpn(ri->ewpn)))
5581 48464 ret=((int32_t)(((weapon*)(s))->xofs))*10000;
5582
5583 48464 break;
5584
5585 case EWPNYOFS:
5586
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60558 times.
60558 if(0!=(s=checkEWpn(ri->ewpn)))
5587
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60558 times.
60558 ret=((int32_t)(((weapon*)(s))->yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset)))*10000;
5588
5589 60558 break;
5590
5591 case EWPNSHADOWXOFS:
5592 if(0!=(s=checkEWpn(ri->ewpn)))
5593 ret=((int32_t)(((weapon*)(s))->shadowxofs))*10000;
5594
5595 break;
5596
5597 case EWPNSHADOWYOFS:
5598 if(0!=(s=checkEWpn(ri->ewpn)))
5599 ret=((int32_t)(((weapon*)(s))->shadowyofs))*10000;
5600
5601 break;
5602 case EWPNTOTALDYOFFS:
5603 if(0!=(s=checkEWpn(ri->ewpn)))
5604 ret = ((int32_t)(((weapon*)(s))->yofs-(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset))
5605 + ((((weapon*)(s))->switch_hooked && Hero.switchhookstyle == swRISE)
5606 ? -(8-(abs(Hero.switchhookclk-32)/4)) : 0) * 10000);
5607 break;
5608
5609 case EWPNZOFS:
5610
1/2
✓ Branch 0 taken 1880 times.
✗ Branch 1 not taken.
1880 if(0!=(s=checkEWpn(ri->ewpn)))
5611 1880 ret=((int32_t)(((weapon*)(s))->zofs))*10000;
5612
5613 1880 break;
5614
5615 case EWPNHXSZ:
5616
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 149564 times.
149564 if(0!=(s=checkEWpn(ri->ewpn)))
5617 149564 ret=(((weapon*)(s))->hit_width)*10000;
5618
5619 149564 break;
5620
5621 case EWPNHYSZ:
5622
1/2
✓ Branch 0 taken 149564 times.
✗ Branch 1 not taken.
149564 if(0!=(s=checkEWpn(ri->ewpn)))
5623 149564 ret=(((weapon*)(s))->hit_height)*10000;
5624
5625 149564 break;
5626
5627 case EWPNHZSZ:
5628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 81355 times.
81355 if(0!=(s=checkEWpn(ri->ewpn)))
5629 81355 ret=(((weapon*)(s))->hzsz)*10000;
5630
5631 81355 break;
5632
5633 case EWPNTXSZ:
5634
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 125257 times.
125257 if(0!=(s=checkEWpn(ri->ewpn)))
5635 125257 ret=(((weapon*)(s))->txsz)*10000;
5636
5637 125257 break;
5638
5639 case EWPNTYSZ:
5640
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 125257 times.
125257 if(0!=(s=checkEWpn(ri->ewpn)))
5641 125257 ret=(((weapon*)(s))->tysz)*10000;
5642
5643 125257 break;
5644
5645 case EWPNCOLLDET:
5646
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10565 times.
10565 if(0!=(s=checkEWpn(ri->ewpn)))
5647 10565 ret=(((weapon*)(s))->scriptcoldet)*10000;
5648
5649 10565 break;
5650
5651 case EWPNENGINEANIMATE:
5652 if(0!=(s=checkEWpn(ri->ewpn)))
5653 ret=(((weapon*)(s))->do_animation)*10000;
5654
5655 break;
5656
5657 case EWPNPARENT:
5658 if(0!=(s=checkEWpn(ri->ewpn)))
5659 ret= ((get_qr(qr_OLDEWPNPARENT)) ? (((weapon*)(s))->parentid)*10000 : (((weapon*)(s))->parentid));
5660
5661 break;
5662
5663 case EWEAPONSCRIPTUID:
5664 if(0!=(s=checkEWpn(ri->ewpn)))
5665 ret=(((weapon*)(s))->getUID());
5666
5667 break;
5668
5669 case EWPNPARENTUID:
5670 if(0!=(s=checkEWpn(ri->ewpn)))
5671 ret = s->parent ? s->parent->getUID() : 0;
5672
5673 break;
5674
5675 case EWPNSCRIPT:
5676
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if(0!=(s=checkEWpn(ri->ewpn)))
5677 43 ret=(((weapon*)(s))->weaponscript)*10000;
5678
5679 43 break;
5680
5681 case EWPNFALLCLK:
5682 if(0!=(s=checkEWpn(ri->ewpn)))
5683 {
5684 ret = ((weapon*)(s))->fallclk * 10000;
5685 }
5686 break;
5687
5688 case EWPNFALLCMB:
5689 if(0!=(s=checkEWpn(ri->ewpn)))
5690 {
5691 ret = ((weapon*)(s))->fallCombo * 10000;
5692 }
5693 break;
5694
5695 case EWPNDROWNCLK:
5696 if(0!=(s=checkEWpn(ri->ewpn)))
5697 {
5698 ret = ((weapon*)(s))->drownclk * 10000;
5699 }
5700 break;
5701
5702 case EWPNDROWNCMB:
5703 if(0!=(s=checkEWpn(ri->ewpn)))
5704 {
5705 ret = ((weapon*)(s))->drownCombo * 10000;
5706 }
5707 break;
5708 case EWPNFAKEZ:
5709 if(0!=(s=checkEWpn(ri->ewpn)))
5710 {
5711 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
5712 {
5713 ret=(((weapon*)(s))->fakez).getZLong();
5714 }
5715 else
5716 ret=((int32_t)((weapon*)(s))->fakez)*10000;
5717 }
5718 break;
5719
5720 case EWPNGLOWRAD:
5721
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30735 times.
30735 if(0!=(s=checkEWpn(ri->ewpn)))
5722 {
5723 30735 ret = ((weapon*)(s))->glowRad * 10000;
5724 30735 }
5725 30735 break;
5726
5727 case EWPNGLOWSHP:
5728 if(0!=(s=checkEWpn(ri->ewpn)))
5729 {
5730 ret = ((weapon*)(s))->glowShape * 10000;
5731 }
5732 break;
5733
5734 case EWPNUNBL:
5735 if(0!=(s=checkEWpn(ri->ewpn)))
5736 {
5737 ret = ((weapon*)(s))->unblockable * 10000;
5738 }
5739 break;
5740
5741 case EWPNSHADOWSPR:
5742 if(0!=(s=checkEWpn(ri->ewpn)))
5743 {
5744 ret = ((weapon*)(s))->spr_shadow * 10000;
5745 }
5746 break;
5747 case EWSWHOOKED:
5748 if(0!=(s=checkEWpn(ri->ewpn)))
5749 {
5750 ret = s->switch_hooked ? 10000 : 0;
5751 }
5752 break;
5753 case EWPNTIMEOUT:
5754 if(0!=(s=checkEWpn(ri->ewpn)))
5755 {
5756 ret = ((weapon*)(s))->weap_timeout * 10000;
5757 }
5758 break;
5759 case EWPNDEATHITEM:
5760 if(0!=(s=checkEWpn(ri->ewpn)))
5761 {
5762 ret = ((weapon*)(s))->death_spawnitem * 10000;
5763 }
5764 break;
5765 case EWPNDEATHDROPSET:
5766 if(0!=(s=checkEWpn(ri->ewpn)))
5767 {
5768 ret = ((weapon*)(s))->death_spawndropset * 10000;
5769 }
5770 break;
5771 case EWPNDEATHIPICKUP:
5772 if(0!=(s=checkEWpn(ri->ewpn)))
5773 {
5774 ret = ((weapon*)(s))->death_item_pflags * 10000;
5775 }
5776 break;
5777 case EWPNDEATHSPRITE:
5778 if(0!=(s=checkEWpn(ri->ewpn)))
5779 {
5780 ret = ((weapon*)(s))->death_sprite * 10000;
5781 }
5782 break;
5783 case EWPNDEATHSFX:
5784 if(0!=(s=checkEWpn(ri->ewpn)))
5785 {
5786 ret = ((weapon*)(s))->death_sfx * 10000;
5787 }
5788 break;
5789 case EWPNLIFTLEVEL:
5790 if(0!=(s=checkEWpn(ri->ewpn)))
5791 {
5792 ret = ((weapon*)(s))->lift_level * 10000;
5793 }
5794 break;
5795 case EWPNLIFTTIME:
5796 if(0!=(s=checkEWpn(ri->ewpn)))
5797 {
5798 ret = ((weapon*)(s))->lift_time * 10000;
5799 }
5800 break;
5801 case EWPNLIFTHEIGHT:
5802 if(0!=(s=checkEWpn(ri->ewpn)))
5803 {
5804 ret = ((weapon*)(s))->lift_height.getZLong();
5805 }
5806 break;
5807
5808 case GETPIXEL:
5809 ret=FFCore.do_getpixel();
5810 break;
5811
5812 case SCREENSCRDATASIZE:
5813 {
5814 int index = map_screen_index(cur_map, ri->screenref);
5815 if (index < 0) break;
5816 ret = 10000*game->scriptDataSize(index);
5817 break;
5818 }
5819
5820 case DISTANCE:
5821 {
5822 792465 double x1 = double(ri->d[rSFTEMP] / 10000.0);
5823 792465 double y1 = double(ri->d[rINDEX] / 10000.0);
5824 792465 double x2 = double(ri->d[rINDEX2] / 10000.0);
5825 792465 double y2 = double(ri->d[rEXP1] / 10000.0);
5826
5827
5828
5829 792465 int32_t result = FFCore.Distance(x1, y1, x2, y2);
5830 792465 ret = (result);
5831
5832 792465 break;
5833 }
5834 case LONGDISTANCE:
5835 {
5836 double x1 = double(ri->d[rSFTEMP]);
5837 double y1 = double(ri->d[rINDEX]);
5838 double x2 = double(ri->d[rINDEX2]);
5839 double y2 = double(ri->d[rEXP1]);
5840
5841
5842
5843 int32_t result = FFCore.LongDistance(x1, y1, x2, y2);
5844 ret = (result);
5845
5846 break;
5847 }
5848
5849 case DISTANCESCALE:
5850 {
5851 double x1 = (double)(ri->d[rSFTEMP] / 10000.0);
5852 double y1 = (double)(ri->d[rINDEX] / 10000.0);
5853 double x2 = (double)(ri->d[rINDEX2] / 10000.0);
5854 double y2 = (double)(ri->d[rEXP1] / 10000.0);
5855
5856 int32_t scale = (ri->d[rWHAT_NO_7]/10000);
5857
5858 if ( !scale ) scale = 10000;
5859 int32_t result = FFCore.Distance(x1, y1, x2, y2, scale);
5860 ret = (result);
5861
5862 break;
5863 }
5864 case LONGDISTANCESCALE:
5865 {
5866 double x1 = (double)(ri->d[rSFTEMP]);
5867 double y1 = (double)(ri->d[rINDEX]);
5868 double x2 = (double)(ri->d[rINDEX2]);
5869 double y2 = (double)(ri->d[rEXP1]);
5870
5871 int32_t scale = (ri->d[rWHAT_NO_7]);
5872
5873 if ( !scale ) scale = 1;
5874 int32_t result = FFCore.LongDistance(x1, y1, x2, y2, scale);
5875 ret = (result);
5876
5877 break;
5878 }
5879
5880 // Note: never used?
5881 case GAMEGUYCOUNTD:
5882 {
5883 int mi = mapind(cur_map, ri->d[rINDEX] / 10000);
5884 ret = game->guys[mi] * 10000;
5885 break;
5886 }
5887
5888 case ALLOCATEBITMAPR:
5889 225 ret=FFCore.get_free_bitmap();
5890 225 break;
5891
5892 case GETMIDI:
5893 63717 ret=(currmidi-(ZC_MIDI_COUNT-1))*10000;
5894 63717 break;
5895
5896 case CURDSCR:
5897 {
5898 11271182 int32_t di = (get_currscr()-DMaps[get_currdmap()].xoff);
5899
2/2
✓ Branch 0 taken 4461127 times.
✓ Branch 1 taken 6810055 times.
11271182 ret=(DMaps[get_currdmap()].type==dmOVERW ? cur_screen : di)*10000;
5900 }
5901 11271182 break;
5902
5903 case GAMEMAXMAPS:
5904 96 ret = (map_count)*10000;
5905 96 break;
5906 case GAMENUMMESSAGES:
5907 ret = (msg_count-1) * 10000;
5908 break;
5909
5910 case CURDMAP:
5911 58184223 ret=cur_dmap*10000;
5912 58184223 break;
5913
5914 case CURLEVEL:
5915 15080301 ret=DMaps[get_currdmap()].level*10000;
5916 15080301 break;
5917
5918 case GAMECLICKFREEZE:
5919 ret=disableClickToFreeze?0:10000;
5920 break;
5921
5922
5923 case NOACTIVESUBSC:
5924 ret=Hero.stopSubscreenFalling()?10000:0;
5925 break;///----------------------------------------------------------------------------------------------------//
5926 //BottleTypes
5927
5928 case BOTTLENEXT:
5929 {
5930 if(bottletype* ptr = checkBottleData(ri->bottletyperef))
5931 {
5932 ret = 10000L * ptr->next_type;
5933 }
5934 else ret = -10000L;
5935 }
5936 break;
5937
5938 ///----------------------------------------------------------------------------------------------------//
5939 //Region
5940
5941 case REGION_WIDTH:
5942 {
5943 47264 ret = world_w * 10000;
5944 }
5945 47264 break;
5946
5947 case REGION_HEIGHT:
5948 {
5949 39568 ret = world_h * 10000;
5950 }
5951 39568 break;
5952
5953 case REGION_SCREEN_WIDTH:
5954 {
5955 64 ret = cur_region.screen_width * 10000;
5956 }
5957 64 break;
5958
5959 case REGION_SCREEN_HEIGHT:
5960 {
5961 20 ret = cur_region.screen_height * 10000;
5962 }
5963 20 break;
5964
5965 case REGION_NUM_COMBOS:
5966 {
5967 32 ret = region_num_rpos * 10000;
5968 }
5969 32 break;
5970
5971 case REGION_ID:
5972 {
5973 982758 ret = get_current_region_id() * 10000;
5974 }
5975 982758 break;
5976
5977 case REGION_ORIGIN_SCREEN:
5978 {
5979 ret = cur_screen;
5980 }
5981 break;
5982
5983 ///----------------------------------------------------------------------------------------------------//
5984 //Viewport
5985
5986 case VIEWPORT_TARGET:
5987 {
5988 ret = get_viewport_sprite()->uid;
5989 }
5990 break;
5991
5992 case VIEWPORT_MODE:
5993 {
5994 ret = (int)viewport_mode;
5995 }
5996 break;
5997
5998 case VIEWPORT_X:
5999 {
6000 24940 ret = viewport.x * 10000;
6001 }
6002 24940 break;
6003
6004 case VIEWPORT_Y:
6005 {
6006 21112 ret = viewport.y * 10000;
6007 }
6008 21112 break;
6009
6010 case VIEWPORT_WIDTH:
6011 {
6012 8014 ret = viewport.w * 10000;
6013 }
6014 8014 break;
6015
6016 case VIEWPORT_HEIGHT:
6017 {
6018 11842 ret = viewport.h * 10000;
6019 }
6020 11842 break;
6021
6022 ///----------------------------------------------------------------------------------------------------//
6023 //Screen Information
6024
6025 #define GET_SCREENDATA_VAR_INT32(member) \
6026 { \
6027 ret = (get_scr(ri->screenref)->member *10000); \
6028 } \
6029
6030 #define GET_SCREENDATA_VAR_INT16(member) \
6031 { \
6032 ret = (get_scr(ri->screenref)->member *10000); \
6033 } \
6034
6035 #define GET_SCREENDATA_VAR_BYTE(member) \
6036 { \
6037 ret = (get_scr(ri->screenref)->member *10000); \
6038 } \
6039
6040 #define GET_SCREENDATA_BYTE_INDEX(member, indexbound) \
6041 { \
6042 int32_t indx = ri->d[rINDEX] / 10000; \
6043 ret = (get_scr(ri->screenref)->member[indx] *10000); \
6044 } \
6045
6046 //byte
6047 #define GET_SCREENDATA_LAYER_INDEX(member, indexbound) \
6048 { \
6049 int32_t indx = ri->d[rINDEX] / 10000; \
6050 if (BC::checkIndex(indx, 1, indexbound) != SH::_NoError) \
6051 { \
6052 ret = -10000; \
6053 } \
6054 else \
6055 { \
6056 ret = (get_scr(ri->screenref)->member[indx-1] *10000); \
6057 } \
6058 } \
6059
6060 #define GET_SCREENDATA_BOOL_INDEX(member, indexbound) \
6061 { \
6062 int32_t indx = ri->d[rINDEX] / 10000; \
6063 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
6064 { \
6065 ret = -10000; \
6066 } \
6067 else \
6068 { \
6069 ret = (get_scr(ri->screenref)->member[indx]?10000:0); \
6070 } \
6071 } \
6072
6073
6074 #define GET_SCREENDATA_FLAG(member, str, indexbound) \
6075 { \
6076 int32_t flag = (value/10000); \
6077 ret = (get_scr(ri->screenref)->member&flag) ? 10000 : 0); \
6078 } \
6079
6080 case SCREENDATAVALID: GET_SCREENDATA_VAR_BYTE(valid); break; //b
6081 case SCREENDATAGUY: GET_SCREENDATA_VAR_BYTE(guy); break; //b
6082 case SCREENDATASTRING: GET_SCREENDATA_VAR_INT32(str); break; //w
6083 case SCREENDATAROOM: GET_SCREENDATA_VAR_BYTE(room); break; //b
6084 case SCREENDATAITEM:
6085 {
6086 mapscr* scr = get_scr(ri->screenref);
6087 if(scr->hasitem)
6088 ret = (scr->item *10000);
6089 else ret = -10000;
6090 break;
6091 }
6092 case SCREENDATAHASITEM: GET_SCREENDATA_VAR_BYTE(hasitem); break; //b
6093 case SCREENDATADOORCOMBOSET: GET_SCREENDATA_VAR_INT32(door_combo_set); break; //w
6094 case SCREENDATAWARPRETURNC: GET_SCREENDATA_VAR_INT32(warpreturnc); break; //w
6095 case SCREENDATASTAIRX: GET_SCREENDATA_VAR_BYTE(stairx); break; //b
6096 case SCREENDATASTAIRY: GET_SCREENDATA_VAR_BYTE(stairy); break; //b
6097 case SCREENDATAITEMX: GET_SCREENDATA_VAR_BYTE(itemx); break; //itemx
6098 case SCREENDATAITEMY: GET_SCREENDATA_VAR_BYTE(itemy); break; //itemy
6099 1026 case SCREENDATACOLOUR: GET_SCREENDATA_VAR_INT32(color); break; //w
6100 case SCREENDATAENEMYFLAGS: GET_SCREENDATA_VAR_BYTE(flags11); break; //b
6101 // Note: never used?
6102 case SCREENDATADOOR: GET_SCREENDATA_BYTE_INDEX(door, 3); break; //b, 4 of these
6103 case SCREENDATAEXITDIR: GET_SCREENDATA_VAR_BYTE(exitdir); break; //b
6104 case SCREENDATAPATTERN: GET_SCREENDATA_VAR_BYTE(pattern); break; //b
6105 case SCREENDATAWARPARRIVALX: GET_SCREENDATA_VAR_BYTE(warparrivalx); break; //b
6106 case SCREENDATAWARPARRIVALY: GET_SCREENDATA_VAR_BYTE(warparrivaly); break; //b
6107 case SCREENDATASIDEWARPINDEX: GET_SCREENDATA_VAR_BYTE(sidewarpindex); break; //b
6108 case SCREENDATAUNDERCOMBO: GET_SCREENDATA_VAR_INT32(undercombo); break; //w
6109 case SCREENDATAUNDERCSET: GET_SCREENDATA_VAR_BYTE(undercset); break; //b
6110 case SCREENDATACATCHALL: GET_SCREENDATA_VAR_INT32(catchall); break; //W
6111
6112 case SCREENDATACSENSITIVE: GET_SCREENDATA_VAR_BYTE(csensitive); break; //B
6113 case SCREENDATANORESET: GET_SCREENDATA_VAR_INT32(noreset); break; //W
6114 case SCREENDATANOCARRY: GET_SCREENDATA_VAR_INT32(nocarry); break; //W
6115 case SCREENDATATIMEDWARPTICS: GET_SCREENDATA_VAR_INT32(timedwarptics); break; //W
6116 case SCREENDATANEXTMAP: GET_SCREENDATA_VAR_BYTE(nextmap); break; //B
6117 case SCREENDATANEXTSCREEN: GET_SCREENDATA_VAR_BYTE(nextscr); break; //B
6118 case SCREENDATAVIEWX: break;//GET_SCREENDATA_VAR_INT32(viewX, "ViewX"); break; //W
6119 case SCREENDATAVIEWY: break;//GET_SCREENDATA_VAR_INT32(viewY, "ViewY"); break; //W
6120 case SCREENDATASCREENWIDTH: break;//GET_SCREENDATA_VAR_BYTE(scrWidth, "Width"); break; //B
6121 case SCREENDATASCREENHEIGHT: break;//GET_SCREENDATA_VAR_BYTE(scrHeight, "Height"); break; //B
6122 case SCREENDATAENTRYX: GET_SCREENDATA_VAR_BYTE(entry_x); break; //B
6123 case SCREENDATAENTRYY: GET_SCREENDATA_VAR_BYTE(entry_y); break; //B
6124 //Number of ffcs that are in use (have valid data
6125 // Note: that is totally not what its doing.
6126 case SCREENDATANUMFF:
6127 {
6128 int id = ri->d[rINDEX] / 10000;
6129 if (auto ffc = ResolveFFCWithID(id))
6130 ret = ffc->data != 0 ? 10000 : 0;
6131 break;
6132 }
6133
6134 // Note: never used?
6135 case SCREENDATAFFINITIALISED: {
6136 int32_t indx = ri->d[rINDEX] / 10000;
6137 if (indx < 0 || indx > MAX_FFCID)
6138 {
6139 scripting_log_error_with_context("Invalid index: %d", (indx));
6140 ret = -10000;
6141 }
6142 else
6143 {
6144 ret = get_script_engine_data(ScriptType::FFC, indx).initialized ? 10000 : 0;
6145 }
6146 }
6147 break;
6148
6149 case SCREENDATASCRIPTENTRY:
6150 {
6151 Z_scripterrlog("Unimplemented: %s\n", "ScriptEntry");
6152 ret = -10000;
6153 }
6154 break;
6155 case SCREENDATASCRIPTOCCUPANCY:
6156 {
6157 Z_scripterrlog("Unimplemented: %s\n", "ScriptOccupancy");
6158 ret = -10000;
6159 }
6160 break;
6161 case SCREENDATASCRIPTEXIT:
6162 {
6163 Z_scripterrlog("Unimplemented: %s\n", "ExitScript");
6164 ret = -10000;
6165 }
6166 break;
6167
6168 case SCREENDATAOCEANSFX: GET_SCREENDATA_VAR_BYTE(oceansfx); break; //B
6169 case SCREENDATABOSSSFX: GET_SCREENDATA_VAR_BYTE(bosssfx); break; //B
6170 17 case SCREENDATASECRETSFX: GET_SCREENDATA_VAR_BYTE(secretsfx); break; //B
6171 case SCREENDATAHOLDUPSFX: GET_SCREENDATA_VAR_BYTE(holdupsfx); break; //B
6172 case SCREENDATASCREENMIDI:
6173 {
6174 ret = ((get_scr(ri->screenref)->screen_midi+(MIDIOFFSET_MAPSCR-MIDIOFFSET_ZSCRIPT)) *10000);
6175 break;
6176 }
6177 case SCREENDATALENSLAYER: GET_SCREENDATA_VAR_BYTE(lens_layer); break; //B, OLD QUESTS ONLY?
6178
6179 case SCREENSECRETSTRIGGERED:
6180 {
6181 910 ret = get_screen_state(ri->screenref).triggered_secrets ? 10000L : 0L;
6182 910 break;
6183 }
6184
6185 case SCREENDATAGUYCOUNT:
6186 {
6187 int mi = mapind(cur_map, ri->screenref);
6188 if(mi < 0)
6189 ret = -10000;
6190 else ret = game->guys[mi] * 10000;
6191 break;
6192 }
6193 case SCREENDATAEXDOOR:
6194 {
6195 ret = 0;
6196 int mi = mapind(cur_map, ri->screenref);
6197 if(mi < 0) break;
6198 int dir = SH::read_stack(ri->sp+1) / 10000;
6199 int ind = SH::read_stack(ri->sp+0) / 10000;
6200 if(unsigned(dir) > 3)
6201 Z_scripterrlog("Invalid dir '%d' passed to 'Screen->GetExDoor()'; must be 0-3\n", dir);
6202 else if(unsigned(ind) > 7)
6203 Z_scripterrlog("Invalid index '%d' passed to 'Screen->GetExDoor()'; must be 0-7\n", ind);
6204 else
6205 {
6206 int bit = 1<<ind;
6207 ret = (game->xdoors[mi][dir]&bit) ? 10000 : 0;
6208 }
6209 break;
6210 }
6211
6212 case SHOWNMSG:
6213 {
6214
4/4
✓ Branch 0 taken 1832 times.
✓ Branch 1 taken 7660 times.
✓ Branch 2 taken 1800 times.
✓ Branch 3 taken 32 times.
9492 ret = ((msg_active || msg_onscreen) ? msgstr : 0) * 10000L;
6215 9492 break;
6216 }
6217
6218 case SDDD:
6219 43250 ret=FFScript::get_screen_d((ri->d[rINDEX])/10000 + ((get_currdmap())<<7), ri->d[rINDEX2] / 10000);
6220 43250 break;
6221
6222 case LINKOTILE:
6223 ret=FFCore.getHeroOTile(ri->d[rINDEX]/10000, ri->d[rINDEX2] / 10000);
6224 break;
6225
6226 case SDDDD:
6227 6 ret=FFScript::get_screen_d(ri->d[rINDEX2] / 10000 + ((ri->d[rINDEX]/10000)<<7), ri->d[rEXP1] / 10000);
6228 6 break;
6229
6230 case SCREENSCRIPT:
6231 ret=get_scr(ri->screenref)->script*10000;
6232 break;
6233
6234 //These use the same method as GetScreenD -Z
6235 case SCREENWIDTH:
6236 // ret=FFScript::get_screenWidth(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)]);
6237 break;
6238
6239 case SCREENHEIGHT:
6240 // ret=FFScript::get_screenHeight(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)]);
6241 break;
6242
6243 case SCREENVIEWX:
6244 // ret=get_screenViewX(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)]);
6245 break;
6246
6247 case SCREENVIEWY:
6248 // ret=get_screenViewY(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)]);
6249 break;
6250
6251 case LIT:
6252 10246 ret= get_lights() ? 10000 : 0;
6253 10246 break;
6254
6255 case WAVY:
6256 7214 ret = wavy*10000;
6257 7214 break;
6258
6259 case QUAKE:
6260 2391 ret = quakeclk*10000;
6261 2391 break;
6262
6263 case NPCCOUNT:
6264 25369889 ret = guys.Count()*10000;
6265 25369889 break;
6266
6267 case ROOMDATA:
6268 47 ret = get_scr(ri->screenref)->catchall*10000;
6269 47 break;
6270
6271 case ROOMTYPE:
6272 2 ret = get_scr(ri->screenref)->room*10000;
6273 2 break;
6274
6275 case PUSHBLOCKX:
6276
2/2
✓ Branch 0 taken 3584 times.
✓ Branch 1 taken 339575 times.
343159 ret = mblock2.active() ? int32_t(mblock2.x)*10000 : -10000;
6277 343159 break;
6278
6279 case PUSHBLOCKY:
6280
2/2
✓ Branch 0 taken 2943 times.
✓ Branch 1 taken 98007 times.
100950 ret = mblock2.active() ? int32_t(mblock2.y)*10000 : -10000;
6281 100950 break;
6282
6283 case PUSHBLOCKLAYER:
6284 ret = mblock2.active() ? int32_t(mblock2.blockLayer)*10000 : -10000;
6285 break;
6286
6287 case PUSHBLOCKCOMBO:
6288 ret = mblock2.bcombo*10000;
6289 break;
6290
6291 case PUSHBLOCKCSET:
6292 ret = mblock2.cs*10000;
6293 break;
6294
6295 case UNDERCOMBO:
6296 1636 ret = get_scr(ri->screenref)->undercombo*10000;
6297 1636 break;
6298
6299 case UNDERCSET:
6300 1610 ret = get_scr(ri->screenref)->undercset*10000;
6301 1610 break;
6302
6303 case SCREEN_INDEX:
6304 32 ret = ri->screenref*10000;
6305 32 break;
6306
6307 case SCREEN_DRAW_ORIGIN:
6308 ret = (int)ri->screen_draw_origin;
6309 break;
6310
6311 case SCREEN_DRAW_ORIGIN_TARGET:
6312 ret = ri->screen_draw_origin_target;
6313 break;
6314
6315 //Creates an lweapon using an iemdata struct values to generate its properties.
6316 //Useful in conjunction with the new weapon editor.
6317 case CREATELWPNDX:
6318 {
6319 //Z_message("Trying to get Hero->SetExtend().\n");
6320 int32_t ID = (ri->d[rINDEX] / 10000);
6321 int32_t itemid = (ri->d[rINDEX2]/10000);
6322 itemid = vbound(itemid,0,(MAXITEMS-1));
6323
6324 // TODO: use has_space()
6325 if ( Lwpns.Count() < 256 )
6326 {
6327
6328 (void)Lwpns.add
6329 (
6330 new weapon
6331 (
6332 (zfix)0, /*X*/
6333 (zfix)0, /*Y*/
6334 (zfix)0, /*Z*/
6335 ID, /*id*/
6336 0, /*type*/
6337 0, /*power*/
6338 0, /*dir*/
6339 -1, /*Parentid*/
6340 Hero.getUID(), /*prntid*/
6341 false, /*isdummy*/
6342 1, /*script_gen*/
6343 1, /*islwpn*/
6344 (ID==wWind?1:0) /*special*/
6345 )
6346 );
6347 ri->lwpn = Lwpns.spr(Lwpns.Count() - 1)->getUID();
6348
6349 weapon *w = (weapon*)Lwpns.spr(Lwpns.Count()-1); //last created
6350 //w->LOADGFX(FFCore.getDefWeaponSprite(ID)); //What the fuck Zoria, this broke old quests...
6351 w->ScriptGenerated = 1;
6352 w->isLWeapon = 1;
6353 if(ID == wWind) w->specialinfo = 1;
6354 //weapon *w = (weapon*)Lwpns.spr(Lwpns.Count()-1); //last created
6355 //w->LOADGFX(FFCore.getDefWeaponSprite(ID)); //not needed here because this has access to wpn->prent
6356 }
6357 else
6358 {
6359 Z_scripterrlog("Tried to create too many LWeapons on the screen. The current LWeapon count is: %d\n", Lwpns.Count());
6360 ri->lwpn = 0;
6361 }
6362
6363 ret = ri->lwpn;
6364 }
6365 break;
6366
6367 ///----------------------------------------------------------------------------------------------------//
6368 //New Datatype Variables
6369
6370 ///----------------------------------------------------------------------------------------------------//
6371 //spritedata sp-> Variables
6372
6373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 case SPRITEDATATILE: GET_SPRITEDATA_VAR_INT(tile) break;
6374 case SPRITEDATAMISC: GET_SPRITEDATA_VAR_INT(misc) break;
6375 case SPRITEDATACSETS:
6376 {
6377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if(unsigned(ri->spritedataref) > (MAXWPNS-1) )
6378 {
6379 ret = -10000;
6380 Z_scripterrlog("Invalid Sprite ID passed to spritedata->CSet: %d\n", (ri->spritedataref*10000));
6381 }
6382 else
6383 16 ret = ((wpnsbuf[ri->spritedataref].csets & 0xF) * 10000);
6384 16 break;
6385 }
6386 case SPRITEDATAFLCSET:
6387 {
6388 if(unsigned(ri->spritedataref) > (MAXWPNS-1) )
6389 {
6390 ret = -10000;
6391 Z_scripterrlog("Invalid Sprite ID passed to spritedata->%s: %d\n", (ri->spritedataref*10000), "FlashCSet");
6392 break;
6393 }
6394 ret = (((wpnsbuf[ri->spritedataref].csets & 0xF0)>>4) * 10000);
6395 break;
6396 }
6397
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 case SPRITEDATAFRAMES: GET_SPRITEDATA_VAR_INT(frames) break;
6398
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 case SPRITEDATASPEED: GET_SPRITEDATA_VAR_INT(speed) break;
6399 case SPRITEDATATYPE: GET_SPRITEDATA_VAR_INT(type) break;
6400 case SPRITEDATAID:
6401 {
6402 if(unsigned(ri->spritedataref) > (MAXWPNS-1) )
6403 {
6404 ret = -10000;
6405 Z_scripterrlog("Invalid Sprite ID passed to spritedata->ID: %d\n", (ri->spritedataref*10000));
6406 break;
6407 }
6408 ret = ri->spritedataref*10000;
6409 break;
6410 }
6411
6412 ///----------------------------------------------------------------------------------------------------//
6413 //mapdata m-> variables
6414 #define GET_MAPDATA_VAR_INT32(member) \
6415 { \
6416 if ( mapscr *m = ResolveMapdataScr(ri->mapsref) ) \
6417 { \
6418 ret = (m->member *10000); \
6419 } \
6420 else \
6421 { \
6422 ret = -10000; \
6423 } \
6424 } \
6425
6426 #define GET_MAPDATA_VAR_INT16(member) \
6427 { \
6428 if ( mapscr *m = ResolveMapdataScr(ri->mapsref) ) \
6429 { \
6430 ret = (m->member *10000); \
6431 } \
6432 else \
6433 { \
6434 ret = -10000; \
6435 } \
6436 } \
6437
6438 #define GET_MAPDATA_VAR_BYTE(member) \
6439 { \
6440 if ( mapscr *m = ResolveMapdataScr(ri->mapsref) ) \
6441 { \
6442 ret = (m->member *10000); \
6443 } \
6444 else \
6445 { \
6446 ret = -10000; \
6447 } \
6448 } \
6449
6450 #define GET_MAPDATA_FLAG(member) \
6451 { \
6452 int32_t flag = (value/10000); \
6453 if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
6454 { \
6455 ret = (m->member&flag) ? 10000 : 0); \
6456 } \
6457 else \
6458 { \
6459 ret = -10000; \
6460 } \
6461 } \
6462
6463 #define GET_MAPDATA_FFCPOS_INDEX32(member, indexbound) \
6464 { \
6465 int32_t index = (ri->d[rINDEX] / 10000); \
6466 if (auto handle = ResolveMapdataFFC(ri->mapsref, index)) \
6467 { \
6468 ret = (handle.ffc->member).getZLong(); \
6469 } \
6470 else \
6471 { \
6472 ret = -10000; \
6473 } \
6474 } \
6475
6476 #define GET_MAPDATA_FFC_INDEX32(member, indexbound) \
6477 { \
6478 int32_t index = (ri->d[rINDEX] / 10000); \
6479 if (auto handle = ResolveMapdataFFC(ri->mapsref, index)) \
6480 { \
6481 ret = (handle.ffc->member)*10000; \
6482 } \
6483 else \
6484 { \
6485 ret = -10000; \
6486 } \
6487 } \
6488
6489 #define GET_MAPDATA_FFC_INDEX32(member, indexbound) \
6490 { \
6491 int32_t index = (ri->d[rINDEX] / 10000); \
6492 if (auto handle = ResolveMapdataFFC(ri->mapsref, index)) \
6493 { \
6494 ret = (handle.ffc->member)*10000; \
6495 } \
6496 else \
6497 { \
6498 ret = -10000; \
6499 } \
6500 } \
6501
6502 case LOADMAPDATA:
6503 6567172 ret=FFScript::loadMapData();
6504 6567172 break;
6505
6506 case CREATEBITMAP:
6507 {
6508 3858 ret=FFCore.do_create_bitmap();
6509 3858 break;
6510 }
6511
6512
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 case MAPDATAVALID: GET_MAPDATA_VAR_BYTE(valid); break; //b
6513 case MAPDATAGUY: GET_MAPDATA_VAR_BYTE(guy); break; //b
6514 case MAPDATASTRING: GET_MAPDATA_VAR_INT32(str); break; //w
6515 case MAPDATAROOM: GET_MAPDATA_VAR_BYTE(room); break; //b
6516 case MAPDATAITEM:
6517 {
6518 if ( mapscr *m = ResolveMapdataScr(ri->mapsref) )
6519 {
6520 if(m->hasitem)
6521 ret = (m->item *10000);
6522 else ret = -10000;
6523 }
6524 else
6525 {
6526 ret = -10000;
6527 }
6528 break;
6529 }
6530 case MAPDATAREGIONID:
6531 {
6532 if (auto scr = ResolveMapdataScr(ri->mapsref))
6533 ret = get_region_id(scr->map, scr->screen) * 10000;
6534 break;
6535 }
6536 case MAPDATAHASITEM: GET_MAPDATA_VAR_BYTE(hasitem); break; //b
6537 case MAPDATADOORCOMBOSET: GET_MAPDATA_VAR_INT32(door_combo_set); break; //w
6538 case MAPDATAWARPRETURNC: GET_MAPDATA_VAR_INT32(warpreturnc); break; //w
6539 case MAPDATASTAIRX: GET_MAPDATA_VAR_BYTE(stairx); break; //b
6540 case MAPDATASTAIRY: GET_MAPDATA_VAR_BYTE(stairy); break; //b
6541 case MAPDATAITEMX: GET_MAPDATA_VAR_BYTE(itemx); break; //itemx
6542 case MAPDATAITEMY: GET_MAPDATA_VAR_BYTE(itemy); break; //itemy
6543
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 case MAPDATACOLOUR: GET_MAPDATA_VAR_INT32(color); break; //w
6544 case MAPDATAENEMYFLAGS: GET_MAPDATA_VAR_BYTE(flags11); break; //b
6545 case MAPDATAEXITDIR: GET_MAPDATA_VAR_BYTE(exitdir); break; //b
6546 case MAPDATAPATTERN: GET_MAPDATA_VAR_BYTE(pattern); break; //b
6547 case MAPDATAWARPARRIVALX: GET_MAPDATA_VAR_BYTE(warparrivalx); break; //b
6548 case MAPDATAWARPARRIVALY: GET_MAPDATA_VAR_BYTE(warparrivaly); break; //b
6549 case MAPDATASIDEWARPINDEX: GET_MAPDATA_VAR_BYTE(sidewarpindex); break; //b
6550 case MAPDATAUNDERCOMBO: GET_MAPDATA_VAR_INT32(undercombo); break; //w
6551 case MAPDATAUNDERCSET: GET_MAPDATA_VAR_BYTE(undercset); break; //b
6552 case MAPDATACATCHALL: GET_MAPDATA_VAR_INT32(catchall); break; //W
6553
6554 case MAPDATACSENSITIVE: GET_MAPDATA_VAR_BYTE(csensitive); break; //B
6555 case MAPDATANORESET: GET_MAPDATA_VAR_INT32(noreset); break; //W
6556 case MAPDATANOCARRY: GET_MAPDATA_VAR_INT32(nocarry); break; //W
6557 case MAPDATATIMEDWARPTICS: GET_MAPDATA_VAR_INT32(timedwarptics); break; //W
6558 case MAPDATANEXTMAP: GET_MAPDATA_VAR_BYTE(nextmap); break; //B
6559 case MAPDATANEXTSCREEN: GET_MAPDATA_VAR_BYTE(nextscr); break; //B
6560
6561 case MAPDATAVIEWX: break;//GET_MAPDATA_VAR_INT32(viewX, "ViewX"); break; //W
6562 case MAPDATASCRIPT: GET_MAPDATA_VAR_INT32(script); break; //W
6563 case MAPDATAVIEWY: break;//GET_MAPDATA_VAR_INT32(viewY, "ViewY"); break; //W
6564 case MAPDATASCREENWIDTH: break;//GET_MAPDATA_VAR_BYTE(scrWidth, "Width"); break; //B
6565 case MAPDATASCREENHEIGHT: break;//GET_MAPDATA_VAR_BYTE(scrHeight, "Height"); break; //B
6566 case MAPDATAENTRYX: GET_MAPDATA_VAR_BYTE(entry_x); break; //B
6567 case MAPDATAENTRYY: GET_MAPDATA_VAR_BYTE(entry_y); break; //B
6568
6569 //Number of ffcs that are in use (have valid data
6570 // NOTE: defunct. Never implemented correctly.
6571 case MAPDATANUMFF:
6572 {
6573 32 int index = ri->d[rINDEX] / 10000;
6574
6575
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 if (auto handle = ResolveMapdataFFC(ri->mapsref, index))
6576 {
6577 32 ret = (handle.data() != 0) ? 10000 : 0;
6578 32 }
6579 else
6580 {
6581 ret = 0;
6582 }
6583 32 break;
6584 }
6585
6586 case MAPDATAINTID: //Same form as SetScreenD()
6587 //SetFFCInitD(ffindex, d, value)
6588 {
6589 2004 int32_t index = (ri->d[rINDEX]/10000);
6590 2004 int32_t d_index = ri->d[rINDEX2]/10000;
6591
6592
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2004 times.
2004 if (BC::checkBounds(d_index, 0, 7) != SH::_NoError)
6593 break;
6594
6595
1/2
✓ Branch 0 taken 2004 times.
✗ Branch 1 not taken.
2004 if (auto handle = ResolveMapdataFFC(ri->mapsref, index))
6596 2004 ret = handle.ffc->initd[d_index];
6597 else
6598 {
6599 ret = -10000;
6600 }
6601 2004 break;
6602 }
6603
6604 case MAPDATASCRIPTENTRY:
6605 {
6606 Z_scripterrlog("Unimplemented: %s\n", "ScriptEntry");
6607 ret = -10000;
6608 }
6609 break;
6610 case MAPDATASCRIPTOCCUPANCY:
6611 {
6612 Z_scripterrlog("Unimplemented: %s\n", "ScriptOccupancy");
6613 ret = -10000;
6614 }
6615 break;
6616 case MAPDATASCRIPTEXIT:
6617 {
6618 Z_scripterrlog("Unimplemented: %s\n", "ExitScript");
6619 ret = -10000;
6620 }
6621 break;
6622
6623 case MAPDATAOCEANSFX: GET_MAPDATA_VAR_BYTE(oceansfx); break; //B
6624 case MAPDATABOSSSFX: GET_MAPDATA_VAR_BYTE(bosssfx); break; //B
6625 case MAPDATASECRETSFX: GET_MAPDATA_VAR_BYTE(secretsfx); break; //B
6626 case MAPDATAHOLDUPSFX: GET_MAPDATA_VAR_BYTE(holdupsfx); break; //B
6627 case MAPDATASCREENMIDI:
6628 {
6629 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
6630 {
6631 ret = ((m->screen_midi+(MIDIOFFSET_MAPSCR-MIDIOFFSET_ZSCRIPT)) *10000);
6632 }
6633 else
6634 {
6635 ret = -10000;
6636 }
6637 break;
6638 }
6639 case MAPDATALENSLAYER: GET_MAPDATA_VAR_BYTE(lens_layer); break; //B, OLD QUESTS ONLY?
6640 case MAPDATAMAP:
6641 {
6642
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
6643 {
6644 9 ret = getMap(ri->mapsref) * 10000;
6645 9 }
6646 else
6647 {
6648 ret = -10000;
6649 }
6650 9 break;
6651 }
6652 case MAPDATASCREEN:
6653 {
6654
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
6655 {
6656 21 ret = getScreen(ri->mapsref) * 10000;
6657 21 }
6658 else
6659 {
6660 ret = -10000;
6661 }
6662 21 break;
6663 }
6664 case MAPDATASCRDATASIZE:
6665 {
6666 ret = -10000;
6667 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
6668 {
6669 int index = get_ref_map_index(ri->mapsref);
6670 if (index < 0) break;
6671
6672 ret = 10000*game->scriptDataSize(index);
6673 }
6674 break;
6675 }
6676 case MAPDATAGUYCOUNT:
6677 {
6678 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
6679 {
6680 int mi = get_mi(ri->mapsref);
6681 if(mi > -1)
6682 {
6683 ret = game->guys[mi] * 10000;
6684 break;
6685 }
6686 }
6687 ret = -10000;
6688 break;
6689 }
6690 case MAPDATAEXDOOR:
6691 {
6692 ret = 0;
6693 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
6694 {
6695 int mi = get_mi(ri->mapsref);
6696 if(mi < 0) break;
6697 int dir = SH::read_stack(ri->sp+1) / 10000;
6698 int ind = SH::read_stack(ri->sp+0) / 10000;
6699 if(unsigned(dir) > 3)
6700 Z_scripterrlog("Invalid dir '%d' passed to 'mapdata->GetExDoor()'; must be 0-3\n", dir);
6701 else if(unsigned(ind) > 7)
6702 Z_scripterrlog("Invalid index '%d' passed to 'mapdata->GetExDoor()'; must be 0-7\n", ind);
6703 else
6704 {
6705 int bit = 1<<ind;
6706 ret = (game->xdoors[mi][dir]&bit) ? 10000 : 0;
6707 }
6708 }
6709 break;
6710 }
6711
6712 ///----------------------------------------------------------------------------------------------------//
6713 //shopdata sd-> variables
6714
6715 case SHOPDATATYPE:
6716 {
6717 int32_t ref = ri->shopsref;
6718 if ( ref > NUMINFOSHOPS || ref < 0 ) ret = 0;
6719 else ret = ( ( ref <= NUMSHOPS ) ? 10000 : 20000 );
6720 break;
6721 }
6722
6723 ///----------------------------------------------------------------------------------------------------//
6724 //dmapdata dmd-> variables
6725
6726 //getter
6727 701 case DMAPDATAID: ret = ri->dmapsref*10000; break; //read-only, equal to CurrentDMap
6728
6729 case DMAPDATAMAP: //byte
6730 {
6731 225 ret = ((byte)DMaps[ri->dmapsref].map + 1) * 10000; break;
6732 }
6733 case DMAPDATALEVEL: //word
6734 {
6735 ret = ((word)DMaps[ri->dmapsref].level) * 10000; break;
6736 }
6737 case DMAPDATAOFFSET: //char
6738 {
6739 6 ret = ((char)DMaps[ri->dmapsref].xoff) * 10000; break;
6740 }
6741 case DMAPDATACOMPASS: //byte
6742 {
6743 ret = ((byte)DMaps[ri->dmapsref].compass) * 10000; break;
6744 }
6745 case DMAPDATAPALETTE: //word
6746 {
6747 212 ret = ((word)DMaps[ri->dmapsref].color) * 10000; break;
6748 }
6749 case DMAPSCRIPT: //word
6750 {
6751 19 ret = (DMaps[ri->dmapsref].script) * 10000; break;
6752 }
6753 case DMAPDATAMIDI: //byte
6754 {
6755 ret = (DMaps[ri->dmapsref].midi-MIDIOFFSET_DMAP) * 10000; break;
6756 }
6757 case DMAPDATACONTINUE: //byte
6758 {
6759 ret = ((byte)DMaps[ri->dmapsref].cont) * 10000; break;
6760 }
6761 case DMAPDATATYPE: //byte
6762 {
6763 1124 ret = ((byte)DMaps[ri->dmapsref].type&dmfTYPE) * 10000; break;
6764 }
6765 case DMAPDATASIDEVIEW: //byte
6766 {
6767 1095768 ret = ((DMaps[ri->dmapsref].sideview) ? 10000 : 0); break;
6768 }
6769 case DMAPDATAMUISCTRACK: //byte
6770 {
6771 ret = ((byte)DMaps[ri->dmapsref].tmusictrack) * 10000; break;
6772 }
6773 case DMAPDATASUBSCRA:
6774 {
6775 ret = ((byte)DMaps[ri->dmapsref].active_subscreen) * 10000; break;
6776 }
6777 case DMAPDATASUBSCRP:
6778 {
6779 5120 ret = ((byte)DMaps[ri->dmapsref].passive_subscreen) * 10000; break;
6780 }
6781 case DMAPDATASUBSCRO:
6782 {
6783 ret = ((byte)DMaps[ri->dmapsref].overlay_subscreen) * 10000; break;
6784 }
6785 case DMAPDATAFLAGS: //int32_t
6786 {
6787 ret = (DMaps[ri->dmapsref].flags) * 10000; break;
6788 }
6789 case DMAPDATAMIRRDMAP:
6790 {
6791 ret = (DMaps[ri->dmapsref].mirrorDMap) * 10000; break;
6792 }
6793 case DMAPDATALOOPSTART:
6794 {
6795 ret = (DMaps[ri->dmapsref].tmusic_loop_start); break;
6796 }
6797 case DMAPDATALOOPEND:
6798 {
6799 ret = (DMaps[ri->dmapsref].tmusic_loop_end); break;
6800 }
6801 case DMAPDATAXFADEIN:
6802 {
6803 ret = (DMaps[ri->dmapsref].tmusic_xfade_in * 10000); break;
6804 }
6805 case DMAPDATAXFADEOUT:
6806 {
6807 ret = (DMaps[ri->dmapsref].tmusic_xfade_out * 10000); break;
6808 }
6809 case DMAPDATAINTROSTRINGID:
6810 {
6811 ret = (DMaps[ri->dmapsref].intro_string_id * 10000); break;
6812 }
6813 case MUSICUPDATECOND:
6814 {
6815 ret = ((byte)FFCore.music_update_cond) * 10000; break;
6816 }
6817 case DMAPDATAASUBSCRIPT: //word
6818 {
6819 22016 ret = (DMaps[ri->dmapsref].active_sub_script) * 10000; break;
6820 }
6821 case DMAPDATAMAPSCRIPT: //byte
6822 {
6823 ret = (DMaps[ri->dmapsref].onmap_script) * 10000; break;
6824 }
6825 case DMAPDATAPSUBSCRIPT: //word
6826 {
6827 ret = (DMaps[ri->dmapsref].passive_sub_script) * 10000; break;
6828 }
6829
6830 ///----------------------------------------------------------------------------------------------------//
6831 //messagedata msgd-> variables
6832 case MESSAGEDATANEXT: //W
6833 {
6834 int32_t ID = ri->zmsgref;
6835
6836 if(BC::checkMessage(ID) != SH::_NoError)
6837 {
6838 ret = -10000; break;
6839 }
6840 else
6841 {
6842 ret = ((int32_t)MsgStrings[ID].nextstring) * 10000;
6843 break;
6844 }
6845 }
6846
6847 case MESSAGEDATATILE: //W
6848 {
6849 int32_t ID = ri->zmsgref;
6850
6851 if(BC::checkMessage(ID) != SH::_NoError)
6852 ret = -10000;
6853 else
6854 ret = ((int32_t)MsgStrings[ID].tile) * 10000;
6855 break;
6856 }
6857
6858 case MESSAGEDATACSET: //b
6859 {
6860 int32_t ID = ri->zmsgref;
6861
6862 if(BC::checkMessage(ID) != SH::_NoError)
6863 ret = -10000;
6864 else
6865 ret = ((int32_t)MsgStrings[ID].cset) * 10000;
6866 break;
6867 }
6868 case MESSAGEDATATRANS: //BOOL
6869 {
6870 int32_t ID = ri->zmsgref;
6871
6872 if(BC::checkMessage(ID) != SH::_NoError)
6873 ret = -10000;
6874 else
6875 ret = ((MsgStrings[ID].trans)?10000:0);
6876 break;
6877 }
6878 case MESSAGEDATAFONT: //B
6879 {
6880 int32_t ID = ri->zmsgref;
6881
6882 if(BC::checkMessage(ID) != SH::_NoError)
6883 ret = -10000;
6884 else
6885 ret = (int32_t)MsgStrings[ID].font * 10000;
6886 break;
6887 }
6888 case MESSAGEDATAX: //SHORT
6889 {
6890 int32_t ID = ri->zmsgref;
6891
6892 if(BC::checkMessage(ID) != SH::_NoError)
6893 ret = -10000;
6894 else
6895 ret = ((int32_t)MsgStrings[ID].x) * 10000;
6896 break;
6897 }
6898 case MESSAGEDATAY: //SHORT
6899 {
6900 int32_t ID = ri->zmsgref;
6901
6902 if(BC::checkMessage(ID) != SH::_NoError)
6903 ret = -10000;
6904 else
6905 ret = ((int32_t)MsgStrings[ID].y) * 10000;
6906 break;
6907 }
6908 case MESSAGEDATAW: //UNSIGNED SHORT
6909 {
6910 int32_t ID = ri->zmsgref;
6911
6912 if(BC::checkMessage(ID) != SH::_NoError)
6913 ret = -10000;
6914 else
6915 ret = ((int32_t)MsgStrings[ID].w) * 10000;
6916 break;
6917 }
6918 case MESSAGEDATAH: //UNSIGNED SHORT
6919 {
6920 int32_t ID = ri->zmsgref;
6921
6922 if(BC::checkMessage(ID) != SH::_NoError)
6923 ret = -10000;
6924 else
6925 ret = ((int32_t)MsgStrings[ID].h) * 10000;
6926 break;
6927 }
6928 case MESSAGEDATASFX: //BYTE
6929 {
6930 int32_t ID = ri->zmsgref;
6931
6932 if(BC::checkMessage(ID) != SH::_NoError)
6933 ret = -10000;
6934 else
6935 ret = ((int32_t)MsgStrings[ID].sfx) * 10000;
6936 break;
6937 }
6938 case MESSAGEDATALISTPOS: //WORD
6939 {
6940 int32_t ID = ri->zmsgref;
6941
6942 if(BC::checkMessage(ID) != SH::_NoError)
6943 ret = -10000;
6944 else
6945 ret = ((int32_t)MsgStrings[ID].listpos) * 10000;
6946 break;
6947 }
6948 case MESSAGEDATAVSPACE: //BYTE
6949 {
6950 int32_t ID = ri->zmsgref;
6951
6952 if(BC::checkMessage(ID) != SH::_NoError)
6953 ret = -10000;
6954 else
6955 ret = ((int32_t)MsgStrings[ID].vspace) * 10000;
6956 break;
6957 }
6958 case MESSAGEDATAHSPACE: //BYTE
6959 {
6960 int32_t ID = ri->zmsgref;
6961
6962 if(BC::checkMessage(ID) != SH::_NoError)
6963 ret = -10000;
6964 else
6965 ret = ((int32_t)MsgStrings[ID].hspace) * 10000;
6966 break;
6967 }
6968 case MESSAGEDATAFLAGS: //BYTE
6969 {
6970 int32_t ID = ri->zmsgref;
6971
6972 if(BC::checkMessage(ID) != SH::_NoError)
6973 ret = -10000;
6974 else
6975 ret = ((int32_t)MsgStrings[ID].stringflags) * 10000;
6976 break;
6977 }
6978 case MESSAGEDATAPORTTILE: //INT
6979 {
6980 int32_t ID = ri->zmsgref;
6981
6982 if(BC::checkMessage(ID) != SH::_NoError)
6983 ret = -10000;
6984 else
6985 ret = ((int32_t)MsgStrings[ID].portrait_tile) * 10000;
6986 break;
6987 }
6988 case MESSAGEDATAPORTCSET: //BYTE
6989 {
6990 int32_t ID = ri->zmsgref;
6991
6992 if(BC::checkMessage(ID) != SH::_NoError)
6993 ret = -10000;
6994 else
6995 ret = ((int32_t)MsgStrings[ID].portrait_cset) * 10000;
6996 break;
6997 }
6998 case MESSAGEDATAPORTX: //BYTE
6999 {
7000 int32_t ID = ri->zmsgref;
7001
7002 if(BC::checkMessage(ID) != SH::_NoError)
7003 ret = -10000;
7004 else
7005 ret = ((int32_t)MsgStrings[ID].portrait_x) * 10000;
7006 break;
7007 }
7008 case MESSAGEDATAPORTY: //BYTE
7009 {
7010 int32_t ID = ri->zmsgref;
7011
7012 if(BC::checkMessage(ID) != SH::_NoError)
7013 ret = -10000;
7014 else
7015 ret = ((int32_t)MsgStrings[ID].portrait_y) * 10000;
7016 break;
7017 }
7018 case MESSAGEDATAPORTWID: //BYTE
7019 {
7020 int32_t ID = ri->zmsgref;
7021
7022 if(BC::checkMessage(ID) != SH::_NoError)
7023 ret = -10000;
7024 else
7025 ret = ((int32_t)MsgStrings[ID].portrait_tw) * 10000;
7026 break;
7027 }
7028 case MESSAGEDATAPORTHEI: //BYTE
7029 {
7030 int32_t ID = ri->zmsgref;
7031
7032 if(BC::checkMessage(ID) != SH::_NoError)
7033 ret = -10000;
7034 else
7035 ret = ((int32_t)MsgStrings[ID].portrait_th) * 10000;
7036 break;
7037 }
7038 case MESSAGEDATATEXTLEN: //BYTE
7039 {
7040 int32_t ID = ri->zmsgref;
7041
7042 if(BC::checkMessage(ID) != SH::_NoError)
7043 ret = -10000;
7044 else
7045 ret = int32_t(MsgStrings[ID].s.size()) * 10000;
7046 break;
7047 }
7048 case MESSAGEDATATEXTWID:
7049 {
7050 ret = do_msgwidth(ri->zmsgref)*10000;
7051 break;
7052 }
7053 case MESSAGEDATATEXTHEI:
7054 {
7055 ret = do_msgheight(ri->zmsgref)*10000;
7056 break;
7057 }
7058
7059 ///----------------------------------------------------------------------------------------------------//
7060 //combodata cd-> Getter variables
7061 #define GET_COMBO_VAR_INT(member) \
7062 { \
7063 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7064 { \
7065 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7066 ret = -10000; \
7067 } \
7068 else \
7069 { \
7070 ret = (combobuf[ri->combosref].member *10000); \
7071 } \
7072 } \
7073
7074 #define GET_COMBO_VAR_BYTE(member) \
7075 { \
7076 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7077 { \
7078 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7079 ret = -10000; \
7080 } \
7081 else \
7082 { \
7083 ret = (combobuf[ri->combosref].member *10000); \
7084 } \
7085 } \
7086
7087 #define GET_COMBO_VAR_DWORD(member) \
7088 { \
7089 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7090 { \
7091 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7092 ret = -10000; \
7093 } \
7094 else \
7095 { \
7096 ret = (combobuf[ri->combosref].member *10000); \
7097 } \
7098 } \
7099
7100 #define GET_COMBO_VAR_INDEX(member, indexbound) \
7101 { \
7102 int32_t indx = ri->d[rINDEX] / 10000; \
7103 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7104 { \
7105 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7106 ret = -10000; \
7107 } \
7108 else if ( indx < 0 || indx >= indexbound ) \
7109 { \
7110 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
7111 ret = -10000; \
7112 } \
7113 else \
7114 { \
7115 ret = (combobuf[ri->combosref].member[indx] * 10000); \
7116 } \
7117 }
7118
7119 #define GET_COMBO_BYTE_INDEX(member, indexbound) \
7120 { \
7121 int32_t indx = ri->d[rINDEX] / 10000; \
7122 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7123 { \
7124 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7125 ret = -10000; \
7126 } \
7127 else if ( indx < 0 || indx >= indexbound ) \
7128 { \
7129 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
7130 ret = -10000; \
7131 } \
7132 else \
7133 { \
7134 ret = (combobuf[ri->combosref].member[indx] * 100000); \
7135 } \
7136 }
7137
7138 #define GET_COMBO_FLAG(member, indexbound) \
7139 { \
7140 int32_t flag = (value/10000); \
7141 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7142 { \
7143 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7144 } \
7145 else \
7146 { \
7147 ret = (combobuf[ri->combosref].member&flag) ? 10000 : 0); \
7148 } \
7149 } \
7150
7151 //comboclass macros
7152
7153 #define GET_COMBOCLASS_VAR_INT(member) \
7154 { \
7155 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7156 { \
7157 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7158 ret = -10000; \
7159 } \
7160 else \
7161 { \
7162 ret = (combo_class_buf[combobuf[ri->combosref].type].member *10000); \
7163 } \
7164 } \
7165
7166 #define GET_COMBOCLASS_VAR_BYTE(member) \
7167 { \
7168 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7169 { \
7170 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7171 ret = -10000; \
7172 } \
7173 else \
7174 { \
7175 ret = (combo_class_buf[combobuf[ri->combosref].type].member *10000); \
7176 } \
7177 } \
7178
7179 #define GET_COMBOCLASS_VAR_DWORD(member) \
7180 { \
7181 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7182 { \
7183 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7184 ret = -10000; \
7185 } \
7186 else \
7187 { \
7188 ret = (combo_class_buf[combobuf[ri->combosref].type].member *10000); \
7189 } \
7190 } \
7191
7192 #define GET_COMBOCLASS_VAR_INDEX(member, indexbound) \
7193 { \
7194 int32_t indx = ri->d[rINDEX] / 10000; \
7195 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7196 { \
7197 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7198 ret = -10000; \
7199 } \
7200 else if ( indx < 0 || indx > indexbound ) \
7201 { \
7202 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
7203 ret = -10000; \
7204 } \
7205 else \
7206 { \
7207 ret = (combo_class_buf[combobuf[ri->combosref].type].member[indx] * 10000); \
7208 } \
7209 }
7210
7211 #define GET_COMBOCLASS_BYTE_INDEX(member, indexbound) \
7212 { \
7213 int32_t indx = ri->d[rINDEX] / 10000; \
7214 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7215 { \
7216 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7217 ret = -10000; \
7218 } \
7219 else if ( indx < 0 || indx > indexbound ) \
7220 { \
7221 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
7222 ret = -10000; \
7223 } \
7224 else \
7225 { \
7226 ret = (combo_class_buf[combobuf[ri->combosref].type].member[indx] * 100000); \
7227 } \
7228 }
7229
7230 #define GET_COMBOCLASS_FLAG(member, indexbound) \
7231 { \
7232 int32_t flag = (value/10000); \
7233 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
7234 { \
7235 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
7236 } \
7237 else \
7238 { \
7239 ret = (combo_class_buf[combobuf[ri->combosref].type].member&flag) ? 10000 : 0); \
7240 } \
7241 } \
7242
7243 case COMBOXR:
7244 {
7245 //ri->combosref = id; //'this' pointer
7246 //ri->comboposref = i; //used for X(), Y(), Layer(), and so forth.
7247
1/2
✓ Branch 0 taken 60340 times.
✗ Branch 1 not taken.
60340 if ( curScriptType == ScriptType::Combo )
7248 {
7249 60340 rpos_t rpos = combopos_ref_to_rpos(ri->comboposref);
7250 60340 ret = (( COMBOX_REGION((rpos)) ) * 10000); //comboscriptstack[i]
7251 //this may be wrong...may need a special new var for this, storing the exact combopos
7252 //i is the current script number
7253 60340 }
7254 else
7255 {
7256 scripting_log_error_with_context("Can only be called by combodata scripts, but you tried to use it from script type {}, script token {}", ScriptTypeToString(curScriptType), comboscriptmap[ri->combosref].scriptname);
7257 ret = -10000;
7258 }
7259 60340 break;
7260 }
7261
7262 case COMBOYR:
7263 {
7264
1/2
✓ Branch 0 taken 12211 times.
✗ Branch 1 not taken.
12211 if ( curScriptType == ScriptType::Combo )
7265 {
7266 12211 rpos_t rpos = combopos_ref_to_rpos(ri->comboposref);
7267 12211 ret = (( COMBOY_REGION((rpos)) ) * 10000); //comboscriptstack[i]
7268 12211 }
7269 else
7270 {
7271 scripting_log_error_with_context("Can only be called by combodata scripts, but you tried to use it from script type {}, script token {}", ScriptTypeToString(curScriptType), comboscriptmap[ri->combosref].scriptname); ret = -10000;
7272 }
7273 12211 break;
7274 }
7275 case COMBOPOSR:
7276 {
7277
1/2
✓ Branch 0 taken 208371 times.
✗ Branch 1 not taken.
208371 if ( curScriptType == ScriptType::Combo )
7278 {
7279 208371 rpos_t rpos = combopos_ref_to_rpos(ri->comboposref);
7280 208371 ret = (int)rpos * 10000; //comboscriptstack[i]
7281 208371 }
7282 else
7283 {
7284 scripting_log_error_with_context("Can only be called by combodata scripts, but you tried to use it from script type {}, script token {}", ScriptTypeToString(curScriptType), comboscriptmap[ri->combosref].scriptname); ret = -10000;
7285 }
7286 208371 break;
7287 }
7288 case COMBOLAYERR:
7289 {
7290
1/2
✓ Branch 0 taken 19038 times.
✗ Branch 1 not taken.
19038 if ( curScriptType == ScriptType::Combo )
7291 {
7292 19038 int32_t layer = combopos_ref_to_layer(ri->comboposref);
7293 19038 ret = layer * 10000; //comboscriptstack[i]
7294 19038 }
7295 else
7296 {
7297 scripting_log_error_with_context("Can only be called by combodata scripts, but you tried to use it from script type {}, script token {}", ScriptTypeToString(curScriptType), comboscriptmap[ri->combosref].scriptname); ret = -10000;
7298 }
7299 19038 break;
7300 }
7301
7302 //NEWCOMBO STRUCT
7303
2/4
✓ Branch 0 taken 116988 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 116988 times.
116988 case COMBODTILE: GET_COMBO_VAR_DWORD(tile); break; //word
7304
2/4
✓ Branch 0 taken 112420 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 112420 times.
112420 case COMBODOTILE: GET_COMBO_VAR_DWORD(o_tile); break; //word
7305 case COMBODFRAME: GET_COMBO_VAR_BYTE(cur_frame); break; //char
7306 case COMBODACLK: GET_COMBO_VAR_BYTE(aclk); break; //char
7307 case COMBODASPEED: GET_COMBO_VAR_BYTE(speed); break; //char
7308
2/4
✓ Branch 0 taken 4546 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4546 times.
4546 case COMBODFLIP: GET_COMBO_VAR_BYTE(flip); break; //char
7309 case COMBODWALK:
7310 {
7311
2/4
✓ Branch 0 taken 6890 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6890 times.
6890 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7312 {
7313 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7314 ret = -10000;
7315 }
7316 else
7317 {
7318 6890 ret = ((combobuf[ri->combosref].walk&0x0F) *10000);
7319 }
7320 6890 break;
7321 }
7322 case COMBODEFFECT:
7323 {
7324
2/4
✓ Branch 0 taken 755 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 755 times.
755 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7325 {
7326 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7327 ret = -10000;
7328 }
7329 else
7330 {
7331 755 ret = (((combobuf[ri->combosref].walk&0xF0)>>4) *10000);
7332 }
7333 755 break;
7334 }
7335
2/4
✓ Branch 0 taken 5110 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5110 times.
5110 case COMBODTYPE: GET_COMBO_VAR_BYTE(type); break; //char
7336 case COMBODCSET:
7337 {
7338 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7339 {
7340 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7341 ret = -10000;
7342 }
7343 else
7344 {
7345 bool neg = combobuf[ri->combosref].csets&0x8;
7346 ret = ((combobuf[ri->combosref].csets&0x7) * (neg ? -10000 : 10000));
7347 }
7348 break;
7349 }
7350 case COMBODCSET2FLAGS:
7351 {
7352 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7353 {
7354 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7355 }
7356 else
7357 {
7358 ret = ((combobuf[ri->combosref].csets & 0xF0) >> 4) * 10000;
7359 }
7360 break;
7361 }
7362 case COMBODFOO: break; //W
7363
2/4
✓ Branch 0 taken 463074 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 463074 times.
463074 case COMBODATASCRIPT: GET_COMBO_VAR_DWORD(script); break; //W
7364 case COMBODFRAMES: GET_COMBO_VAR_BYTE(frames); break; //C
7365 case COMBODNEXTD: GET_COMBO_VAR_INT(nextcombo); break; //W
7366 case COMBODNEXTC: GET_COMBO_VAR_BYTE(nextcset); break; //C
7367 case COMBODFLAG: GET_COMBO_VAR_BYTE(flag); break; //C
7368 case COMBODSKIPANIM: GET_COMBO_VAR_BYTE(skipanim); break; //C
7369 case COMBODNEXTTIMER: GET_COMBO_VAR_DWORD(nexttimer); break; //W
7370 case COMBODAKIMANIMY: GET_COMBO_VAR_BYTE(skipanimy); break; //C
7371 case COMBODANIMFLAGS: GET_COMBO_VAR_BYTE(animflags); break; //C
7372
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
18 case COMBODUSRFLAGS: GET_COMBO_VAR_INT(usrflags); break; //LONG
7373 case COMBODTRIGGERITEM:
7374 {
7375 ret = -10000;
7376 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7377 {
7378 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7379 }
7380 else if(auto* trig = get_first_combo_trigger())
7381 ret = trig->triggeritem * 10000;
7382 break;
7383 }
7384 case COMBODTRIGGERTIMER:
7385 {
7386 ret = -10000;
7387 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7388 {
7389 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7390 }
7391 else if(auto* trig = get_first_combo_trigger())
7392 ret = trig->trigtimer * 10000;
7393 break;
7394 }
7395 case COMBODTRIGGERSFX:
7396 {
7397 ret = -10000;
7398 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7399 {
7400 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7401 }
7402 else if(auto* trig = get_first_combo_trigger())
7403 ret = trig->trigsfx * 10000;
7404 break;
7405 }
7406 case COMBODTRIGGERCHANGECMB:
7407 {
7408 ret = -10000;
7409 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7410 {
7411 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7412 }
7413 else if(auto* trig = get_first_combo_trigger())
7414 ret = trig->trigchange * 10000;
7415 break;
7416 }
7417 case COMBODTRIGGERPROX:
7418 {
7419 ret = -10000;
7420 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7421 {
7422 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7423 }
7424 else if(auto* trig = get_first_combo_trigger())
7425 ret = trig->trigprox * 10000;
7426 break;
7427 }
7428 case COMBODTRIGGERLIGHTBEAM:
7429 {
7430 ret = -10000;
7431 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7432 {
7433 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7434 }
7435 else if(auto* trig = get_first_combo_trigger())
7436 ret = trig->triglbeam * 10000;
7437 break;
7438 }
7439 case COMBODTRIGGERCTR:
7440 {
7441 ret = -10000;
7442 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7443 {
7444 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7445 }
7446 else if(auto* trig = get_first_combo_trigger())
7447 ret = trig->trigctr * 10000;
7448 break;
7449 }
7450 case COMBODTRIGGERCTRAMNT:
7451 {
7452 ret = -10000;
7453 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7454 {
7455 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7456 }
7457 else if(auto* trig = get_first_combo_trigger())
7458 ret = trig->trigctramnt * 10000;
7459 break;
7460 }
7461 case COMBODTRIGGERCOOLDOWN:
7462 {
7463 ret = -10000;
7464 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7465 {
7466 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7467 }
7468 else if(auto* trig = get_first_combo_trigger())
7469 ret = trig->trigcooldown * 10000;
7470 break;
7471 }
7472 case COMBODTRIGGERCOPYCAT:
7473 {
7474 ret = -10000;
7475 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7476 {
7477 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7478 }
7479 else if(auto* trig = get_first_combo_trigger())
7480 ret = trig->trigcopycat * 10000;
7481 break;
7482 }
7483 case COMBODTRIGITEMPICKUP:
7484 {
7485 ret = -10000;
7486 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7487 {
7488 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7489 }
7490 else if(auto* trig = get_first_combo_trigger())
7491 ret = trig->spawnip * 10000;
7492 break;
7493 }
7494 case COMBODTRIGEXSTATE:
7495 {
7496 ret = -10000;
7497 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7498 {
7499 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7500 }
7501 else if(auto* trig = get_first_combo_trigger())
7502 ret = trig->exstate * 10000;
7503 break;
7504 }
7505 case COMBODTRIGEXDOORDIR:
7506 {
7507 ret = -10000;
7508 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7509 {
7510 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7511 }
7512 else if(auto* trig = get_first_combo_trigger())
7513 ret = trig->exdoor_dir * 10000;
7514 break;
7515 }
7516 case COMBODTRIGEXDOORIND:
7517 {
7518 ret = -10000;
7519 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7520 {
7521 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7522 }
7523 else if(auto* trig = get_first_combo_trigger())
7524 ret = trig->exdoor_ind * 10000;
7525 break;
7526 }
7527 case COMBODTRIGSPAWNENEMY:
7528 {
7529 ret = -10000;
7530 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7531 {
7532 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7533 }
7534 else if(auto* trig = get_first_combo_trigger())
7535 ret = trig->spawnenemy * 10000;
7536 break;
7537 }
7538 case COMBODTRIGSPAWNITEM:
7539 {
7540 25 ret = -10000;
7541
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 25 times.
25 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7542 {
7543 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7544 }
7545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 else if(auto* trig = get_first_combo_trigger())
7546 25 ret = trig->spawnitem * 10000;
7547 25 break;
7548 }
7549 case COMBODTRIGCSETCHANGE:
7550 {
7551 ret = -10000;
7552 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7553 {
7554 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7555 }
7556 else if(auto* trig = get_first_combo_trigger())
7557 ret = trig->trigcschange * 10000;
7558 break;
7559 }
7560 case COMBODTRIGLITEMS:
7561 {
7562 ret = -10000;
7563 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7564 {
7565 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7566 }
7567 else if(auto* trig = get_first_combo_trigger())
7568 ret = trig->trig_levelitems * 10000;
7569 break;
7570 }
7571 case COMBODTRIGDMAPLVL:
7572 {
7573 ret = -10000;
7574 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7575 {
7576 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7577 }
7578 else if(auto* trig = get_first_combo_trigger())
7579 ret = trig->trigdmlevel * 10000;
7580 break;
7581 }
7582 case COMBODTRIGTINTR:
7583 {
7584 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7585 {
7586 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7587 break;
7588 }
7589 else if(auto* trig = get_first_combo_trigger())
7590 ret = trig->trigtint[0] * 10000;
7591 break;
7592 }
7593 case COMBODTRIGTINTG:
7594 {
7595 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7596 {
7597 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7598 }
7599 else if(auto* trig = get_first_combo_trigger())
7600 ret = trig->trigtint[1] * 10000;
7601 break;
7602 }
7603 case COMBODTRIGTINTB:
7604 {
7605 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7606 {
7607 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7608 }
7609 else if(auto* trig = get_first_combo_trigger())
7610 ret = trig->trigtint[2] * 10000;
7611 break;
7612 }
7613 case COMBODTRIGLVLPAL:
7614 {
7615 ret = -10000;
7616 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7617 {
7618 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7619 }
7620 else if(auto* trig = get_first_combo_trigger())
7621 ret = trig->triglvlpalette * 10000;
7622 break;
7623 }
7624 case COMBODTRIGBOSSPAL:
7625 {
7626 ret = -10000;
7627 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7628 {
7629 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7630 }
7631 else if(auto* trig = get_first_combo_trigger())
7632 ret = trig->trigbosspalette * 10000;
7633 break;
7634 }
7635 case COMBODTRIGQUAKETIME:
7636 {
7637 ret = -10000;
7638 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7639 {
7640 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7641 }
7642 else if(auto* trig = get_first_combo_trigger())
7643 ret = trig->trigquaketime * 10000;
7644 break;
7645 }
7646 case COMBODTRIGWAVYTIME:
7647 {
7648 ret = -10000;
7649 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7650 {
7651 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7652 }
7653 else if(auto* trig = get_first_combo_trigger())
7654 ret = trig->trigwavytime * 10000;
7655 break;
7656 }
7657 case COMBODTRIGSWORDJINX:
7658 {
7659 ret = -10000;
7660 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7661 {
7662 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7663 }
7664 else if(auto* trig = get_first_combo_trigger())
7665 ret = trig->trig_swjinxtime * 10000;
7666 break;
7667 }
7668 case COMBODTRIGITEMJINX:
7669 {
7670 ret = -10000;
7671 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7672 {
7673 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7674 }
7675 else if(auto* trig = get_first_combo_trigger())
7676 ret = trig->trig_itmjinxtime * 10000;
7677 break;
7678 }
7679 case COMBODTRIGSHIELDJINX:
7680 {
7681 ret = -10000;
7682 if (ri->combosref < 0 || ri->combosref >(MAXCOMBOS - 1))
7683 {
7684 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7685 }
7686 else if(auto* trig = get_first_combo_trigger())
7687 ret = trig->trig_shieldjinxtime * 10000;
7688 break;
7689 }
7690 case COMBODTRIGSTUN:
7691 {
7692 ret = -10000;
7693 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7694 {
7695 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7696 }
7697 else if(auto* trig = get_first_combo_trigger())
7698 ret = trig->trig_stuntime * 10000;
7699 break;
7700 }
7701 case COMBODTRIGBUNNY:
7702 {
7703 ret = -10000;
7704 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7705 {
7706 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7707 }
7708 else if(auto* trig = get_first_combo_trigger())
7709 ret = trig->trig_bunnytime * 10000;
7710 break;
7711 }
7712 case COMBODTRIGPUSHTIME:
7713 {
7714 ret = -10000;
7715 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7716 {
7717 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7718 }
7719 else if(auto* trig = get_first_combo_trigger())
7720 ret = trig->trig_pushtime * 10000;
7721 break;
7722 }
7723 case COMBODLIFTGFXCOMBO:
7724 {
7725 ret = -10000;
7726 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7727 {
7728 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7729 }
7730 else ret = (combobuf[ri->combosref].liftcmb) * 10000;
7731 break;
7732 }
7733 case COMBODLIFTGFXCCSET:
7734 {
7735 ret = -10000;
7736 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7737 {
7738 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7739 }
7740 else ret = (combobuf[ri->combosref].liftcs) * 10000;
7741 break;
7742 }
7743 case COMBODLIFTUNDERCMB:
7744 {
7745 ret = -10000;
7746 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7747 {
7748 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7749 }
7750 else ret = (combobuf[ri->combosref].liftundercmb) * 10000;
7751 break;
7752 }
7753 case COMBODLIFTUNDERCS:
7754 {
7755 ret = -10000;
7756 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7757 {
7758 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7759 }
7760 else ret = (combobuf[ri->combosref].liftundercs) * 10000;
7761 break;
7762 }
7763 case COMBODLIFTDAMAGE:
7764 {
7765 ret = -10000;
7766 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7767 {
7768 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7769 }
7770 else ret = (combobuf[ri->combosref].liftdmg) * 10000;
7771 break;
7772 }
7773 case COMBODLIFTLEVEL:
7774 {
7775 ret = -10000;
7776 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7777 {
7778 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7779 }
7780 else ret = (combobuf[ri->combosref].liftlvl) * 10000;
7781 break;
7782 }
7783 case COMBODLIFTITEM:
7784 {
7785 ret = -10000;
7786 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7787 {
7788 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7789 }
7790 else ret = (combobuf[ri->combosref].liftitm) * 10000;
7791 break;
7792 }
7793 case COMBODLIFTGFXTYPE:
7794 {
7795 ret = -10000;
7796 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7797 {
7798 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7799 }
7800 else ret = (combobuf[ri->combosref].liftgfx) * 10000;
7801 break;
7802 }
7803 case COMBODLIFTGFXSPRITE:
7804 {
7805 ret = -10000;
7806 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7807 {
7808 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7809 }
7810 else ret = (combobuf[ri->combosref].liftsprite) * 10000;
7811 break;
7812 }
7813 case COMBODLIFTSFX:
7814 {
7815 ret = -10000;
7816 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7817 {
7818 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7819 }
7820 else ret = (combobuf[ri->combosref].liftsfx) * 10000;
7821 break;
7822 }
7823 case COMBODLIFTBREAKSPRITE:
7824 {
7825 ret = -10000;
7826 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7827 {
7828 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7829 }
7830 else ret = (combobuf[ri->combosref].liftbreaksprite) * 10000;
7831 break;
7832 }
7833 case COMBODLIFTBREAKSFX:
7834 {
7835 ret = -10000;
7836 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7837 {
7838 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7839 }
7840 else ret = (combobuf[ri->combosref].liftbreaksfx) * 10000;
7841 break;
7842 }
7843 case COMBODLIFTHEIGHT:
7844 {
7845 ret = -10000;
7846 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7847 {
7848 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7849 }
7850 else ret = (combobuf[ri->combosref].lifthei) * 10000;
7851 break;
7852 }
7853 case COMBODLIFTTIME:
7854 {
7855 ret = -10000;
7856 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7857 {
7858 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7859 }
7860 else ret = (combobuf[ri->combosref].lifttime) * 10000;
7861 break;
7862 }
7863 case COMBODLIFTLIGHTRAD:
7864 {
7865 ret = -10000;
7866 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7867 {
7868 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7869 }
7870 else ret = (combobuf[ri->combosref].liftlightrad) * 10000;
7871 break;
7872 }
7873 case COMBODLIFTLIGHTSHAPE:
7874 {
7875 ret = -10000;
7876 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7877 {
7878 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7879 }
7880 else ret = (combobuf[ri->combosref].liftlightshape) * 10000;
7881 break;
7882 }
7883 case COMBODLIFTWEAPONITEM:
7884 {
7885 ret = -10000;
7886 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7887 {
7888 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7889 }
7890 else ret = (combobuf[ri->combosref].lift_parent_item) * 10000;
7891 break;
7892 }
7893 case COMBODTRIGGERLSTATE:
7894 {
7895 ret = -10000;
7896 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7897 {
7898 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7899 }
7900 else if(auto* trig = get_first_combo_trigger())
7901 ret = trig->trig_lstate * 10000;
7902 break;
7903 }
7904 case COMBODTRIGGERGSTATE:
7905 {
7906 ret = -10000;
7907 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7908 {
7909 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7910 }
7911 else if(auto* trig = get_first_combo_trigger())
7912 ret = trig->trig_gstate * 10000;
7913 break;
7914 }
7915 case COMBODTRIGGERGROUP:
7916 {
7917 ret = -10000;
7918 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7919 {
7920 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7921 }
7922 else if(auto* trig = get_first_combo_trigger())
7923 ret = trig->trig_group * 10000;
7924 break;
7925 }
7926 case COMBODTRIGGERGROUPVAL:
7927 {
7928 ret = -10000;
7929 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7930 {
7931 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7932 }
7933 else if(auto* trig = get_first_combo_trigger())
7934 ret = trig->trig_group_val * 10000;
7935 break;
7936 }
7937 case COMBODTRIGGERGTIMER:
7938 {
7939 ret = -10000;
7940 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7941 {
7942 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7943 }
7944 else if(auto* trig = get_first_combo_trigger())
7945 ret = trig->trig_statetime * 10000;
7946 break;
7947 }
7948 case COMBODTRIGGERGENSCRIPT:
7949 {
7950 ret = -10000;
7951 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7952 {
7953 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7954 }
7955 else if(auto* trig = get_first_combo_trigger())
7956 ret = trig->trig_genscr * 10000;
7957 break;
7958 }
7959
7960 case COMBODTRIGGERLEVEL:
7961 {
7962 ret = -10000;
7963 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7964 {
7965 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7966 }
7967 else if(auto* trig = get_first_combo_trigger())
7968 ret = trig->triggerlevel * 10000;
7969 break;
7970 }
7971 11602 case COMBODATAID: ret = (ri->combosref*10000); break;
7972 case COMBODNUMTRIGGERS:
7973 {
7974 ret = -10000;
7975 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7976 {
7977 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7978 }
7979 else ret = combobuf[ri->combosref].triggers.size() * 10000;
7980 break;
7981 }
7982 case COMBODONLYGEN:
7983 {
7984 ret = 0;
7985 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
7986 {
7987 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
7988 }
7989 else ret = combobuf[ri->combosref].only_gentrig ? 10000 : 0;
7990 break;
7991 }
7992 //COMBOCLASS STRUCT
7993 //case COMBODNAME: //CHAR[64], STRING
7994 case COMBODBLOCKNPC: GET_COMBOCLASS_VAR_BYTE(block_enemies); break; //C
7995 case COMBODBLOCKHOLE: GET_COMBOCLASS_VAR_BYTE(block_hole); break; //C
7996 case COMBODBLOCKTRIG: GET_COMBOCLASS_VAR_BYTE(block_trigger); break; //C
7997 case COMBODBLOCKWEAPON: GET_COMBOCLASS_BYTE_INDEX(block_weapon, 32); break; //C, 32 INDICES
7998 case COMBODCONVXSPEED: GET_COMBOCLASS_VAR_DWORD(conveyor_x_speed); break; //SHORT
7999 case COMBODCONVYSPEED: GET_COMBOCLASS_VAR_DWORD(conveyor_y_speed); break; //SHORT
8000 case COMBODSPAWNNPC: GET_COMBOCLASS_VAR_DWORD(create_enemy); break; //W
8001 case COMBODSPAWNNPCWHEN: GET_COMBOCLASS_VAR_BYTE(create_enemy_when); break; //C
8002 case COMBODSPAWNNPCCHANGE: GET_COMBOCLASS_VAR_INT(create_enemy_change); break; //LONG
8003 case COMBODDIRCHANGETYPE: GET_COMBOCLASS_VAR_BYTE(directional_change_type); break; //C
8004 case COMBODDISTANCECHANGETILES: GET_COMBOCLASS_VAR_INT(distance_change_tiles); break; //LONG
8005 case COMBODDIVEITEM: GET_COMBOCLASS_VAR_DWORD(dive_item); break; //SHORT
8006 case COMBODDOCK: GET_COMBOCLASS_VAR_BYTE(dock); break; //C
8007 case COMBODFAIRY: GET_COMBOCLASS_VAR_BYTE(fairy); break; //C
8008 case COMBODFFATTRCHANGE: GET_COMBOCLASS_VAR_BYTE(ff_combo_attr_change); break; //C
8009 case COMBODFOORDECOTILE: GET_COMBOCLASS_VAR_INT(foot_decorations_tile); break; //LONG
8010 case COMBODFOORDECOTYPE: GET_COMBOCLASS_VAR_BYTE(foot_decorations_type); break; //C
8011 case COMBODHOOKSHOTPOINT: GET_COMBOCLASS_VAR_BYTE(hookshot_grab_point); break; //C
8012 case COMBODLADDERPASS: GET_COMBOCLASS_VAR_BYTE(ladder_pass); break; //C
8013 case COMBODLOCKBLOCK: GET_COMBOCLASS_VAR_BYTE(lock_block_type); break; //C
8014 case COMBODLOCKBLOCKCHANGE: GET_COMBOCLASS_VAR_INT(lock_block_change); break; //LONG
8015 case COMBODMAGICMIRROR: GET_COMBOCLASS_VAR_BYTE(magic_mirror_type); break; //C
8016 case COMBODMODHPAMOUNT: GET_COMBOCLASS_VAR_DWORD(modify_hp_amount); break; //SHORT
8017 case COMBODMODHPDELAY: GET_COMBOCLASS_VAR_BYTE(modify_hp_delay); break; //C
8018 case COMBODMODHPTYPE: GET_COMBOCLASS_VAR_BYTE(modify_hp_type); break; //C
8019 case COMBODNMODMPAMOUNT: GET_COMBOCLASS_VAR_DWORD(modify_mp_amount); break; //SHORT
8020 case COMBODMODMPDELAY: GET_COMBOCLASS_VAR_BYTE(modify_mp_delay); break; //C
8021 case COMBODMODMPTYPE: GET_COMBOCLASS_VAR_BYTE(modify_mp_type); break; //C
8022 case COMBODNOPUSHBLOCK: GET_COMBOCLASS_VAR_BYTE(no_push_blocks); break; //C
8023 case COMBODOVERHEAD: GET_COMBOCLASS_VAR_BYTE(overhead); break; //C
8024 case COMBODPLACENPC: GET_COMBOCLASS_VAR_BYTE(place_enemy); break; //C
8025 case COMBODPUSHDIR: GET_COMBOCLASS_VAR_BYTE(push_direction); break; //C
8026 case COMBODPUSHWAIT: GET_COMBOCLASS_VAR_BYTE(push_wait); break; //C
8027 case COMBODPUSHHEAVY: GET_COMBOCLASS_VAR_BYTE(push_weight); break; //C
8028 case COMBODPUSHED: GET_COMBOCLASS_VAR_BYTE(pushed); break; //C
8029 case COMBODRAFT: GET_COMBOCLASS_VAR_BYTE(raft); break; //C
8030 case COMBODRESETROOM: GET_COMBOCLASS_VAR_BYTE(reset_room); break; //C
8031 case COMBODSAVEPOINTTYPE: GET_COMBOCLASS_VAR_BYTE(save_point_type); break; //C
8032 case COMBODSCREENFREEZETYPE: GET_COMBOCLASS_VAR_BYTE(screen_freeze_type); break; //C
8033 case COMBODSECRETCOMBO: GET_COMBOCLASS_VAR_BYTE(secret_combo); break; //C
8034 case COMBODSINGULAR: GET_COMBOCLASS_VAR_BYTE(singular); break; //C
8035 case COMBODSLOWWALK: GET_COMBOCLASS_VAR_BYTE(slow_movement); break; //C
8036 case COMBODSTATUETYPE: GET_COMBOCLASS_VAR_BYTE(statue_type); break; //C
8037 case COMBODSTEPTYPE: GET_COMBOCLASS_VAR_BYTE(step_type); break; //C
8038 case COMBODSTEPCHANGEINTO: GET_COMBOCLASS_VAR_INT(step_change_to); break; //LONG
8039 case COMBODSTRIKEWEAPONS: GET_COMBOCLASS_BYTE_INDEX(strike_weapons, 32); break; //BYTE, 32 INDICES.
8040 case COMBODSTRIKEREMNANTS: GET_COMBOCLASS_VAR_INT(strike_remnants); break; //LONG
8041 case COMBODSTRIKEREMNANTSTYPE: GET_COMBOCLASS_VAR_BYTE(strike_remnants_type); break; //C
8042 case COMBODSTRIKECHANGE: GET_COMBOCLASS_VAR_INT(strike_change); break; //LONG
8043 case COMBODSTRIKEITEM: GET_COMBOCLASS_VAR_DWORD(strike_item); break; //SHORT
8044 case COMBODTOUCHITEM: GET_COMBOCLASS_VAR_DWORD(touch_item); break; //SHORT
8045 case COMBODTOUCHSTAIRS: GET_COMBOCLASS_VAR_BYTE(touch_stairs); break; //C
8046 case COMBODTRIGGERTYPE: GET_COMBOCLASS_VAR_BYTE(trigger_type); break; //C
8047 case COMBODTRIGGERSENS: GET_COMBOCLASS_VAR_BYTE(trigger_sensitive); break; //C
8048 case COMBODWARPTYPE: GET_COMBOCLASS_VAR_BYTE(warp_type); break; //C
8049 case COMBODWARPSENS: GET_COMBOCLASS_VAR_BYTE(warp_sensitive); break; //C
8050 case COMBODWARPDIRECT: GET_COMBOCLASS_VAR_BYTE(warp_direct); break; //C
8051 case COMBODWARPLOCATION: GET_COMBOCLASS_VAR_BYTE(warp_location); break; //C
8052 case COMBODWATER: GET_COMBOCLASS_VAR_BYTE(water); break; //C
8053 case COMBODWHISTLE: GET_COMBOCLASS_VAR_BYTE(whistle); break; //C
8054 case COMBODWINGAME: GET_COMBOCLASS_VAR_BYTE(win_game); break; //C
8055 case COMBODBLOCKWPNLEVEL: GET_COMBOCLASS_VAR_BYTE(block_weapon_lvl); break; //C
8056
8057
8058
8059 ///----------------------------------------------------------------------------------------------------//
8060 case CMBTRIGWPNLEVEL:
8061 {
8062 if(auto* trig = get_combo_trigger(ri->combotrigref))
8063 {
8064 ret = trig->triggerlevel * 10000;
8065 }
8066 else ret = -10000;
8067 break;
8068 }
8069 case CMBTRIGREQITEM:
8070 {
8071 if(auto* trig = get_combo_trigger(ri->combotrigref))
8072 {
8073 ret = trig->triggeritem * 10000;
8074 }
8075 else ret = -10000;
8076 break;
8077 }
8078 case CMBTRIGTIMER:
8079 {
8080 if(auto* trig = get_combo_trigger(ri->combotrigref))
8081 {
8082 ret = trig->trigtimer * 10000;
8083 }
8084 else ret = -10000;
8085 break;
8086 }
8087 case CMBTRIGSFX:
8088 {
8089 if(auto* trig = get_combo_trigger(ri->combotrigref))
8090 {
8091 ret = trig->trigsfx * 10000;
8092 }
8093 else ret = -10000;
8094 break;
8095 }
8096 case CMBTRIGCHANGECMB:
8097 {
8098 if(auto* trig = get_combo_trigger(ri->combotrigref))
8099 {
8100 ret = trig->trigchange * 10000;
8101 }
8102 else ret = -10000;
8103 break;
8104 }
8105 case CMBTRIGCSETCHANGE:
8106 {
8107 if(auto* trig = get_combo_trigger(ri->combotrigref))
8108 {
8109 ret = trig->trigcschange * 10000;
8110 }
8111 else ret = -10000;
8112 break;
8113 }
8114 case CMBTRIGPROX:
8115 {
8116 if(auto* trig = get_combo_trigger(ri->combotrigref))
8117 {
8118 ret = trig->trigprox * 10000;
8119 }
8120 else ret = -10000;
8121 break;
8122 }
8123 case CMBTRIGLIGHTBEAM:
8124 {
8125 if(auto* trig = get_combo_trigger(ri->combotrigref))
8126 {
8127 ret = trig->triglbeam * 10000;
8128 }
8129 else ret = -10000;
8130 break;
8131 }
8132 case CMBTRIGCTR:
8133 {
8134 if(auto* trig = get_combo_trigger(ri->combotrigref))
8135 {
8136 ret = trig->trigctr * 10000;
8137 }
8138 else ret = -10000;
8139 break;
8140 }
8141 case CMBTRIGCTRAMNT:
8142 {
8143 if(auto* trig = get_combo_trigger(ri->combotrigref))
8144 {
8145 ret = trig->trigctramnt * 10000;
8146 }
8147 else ret = -10000;
8148 break;
8149 }
8150 case CMBTRIGCOOLDOWN:
8151 {
8152 if(auto* trig = get_combo_trigger(ri->combotrigref))
8153 {
8154 ret = trig->trigcooldown * 10000;
8155 }
8156 else ret = -10000;
8157 break;
8158 }
8159 case CMBTRIGCOPYCAT:
8160 {
8161 if(auto* trig = get_combo_trigger(ri->combotrigref))
8162 {
8163 ret = trig->trigcopycat * 10000;
8164 }
8165 else ret = -10000;
8166 break;
8167 }
8168 case CMBTRIGITEMPICKUP:
8169 {
8170 if(auto* trig = get_combo_trigger(ri->combotrigref))
8171 {
8172 ret = trig->spawnip * 10000;
8173 }
8174 else ret = -10000;
8175 break;
8176 }
8177 case CMBTRIGEXSTATE:
8178 {
8179 if(auto* trig = get_combo_trigger(ri->combotrigref))
8180 {
8181 ret = trig->exstate * 10000;
8182 }
8183 else ret = -10000;
8184 break;
8185 }
8186 case CMBTRIGEXDOORDIR:
8187 {
8188 if(auto* trig = get_combo_trigger(ri->combotrigref))
8189 {
8190 ret = trig->exdoor_dir * 10000;
8191 }
8192 else ret = -10000;
8193 break;
8194 }
8195 case CMBTRIGEXDOORIND:
8196 {
8197 if(auto* trig = get_combo_trigger(ri->combotrigref))
8198 {
8199 ret = trig->exdoor_ind * 10000;
8200 }
8201 else ret = -10000;
8202 break;
8203 }
8204 case CMBTRIGSPAWNENEMY:
8205 {
8206 if(auto* trig = get_combo_trigger(ri->combotrigref))
8207 {
8208 ret = trig->spawnenemy * 10000;
8209 }
8210 else ret = -10000;
8211 break;
8212 }
8213 case CMBTRIGSPAWNITEM:
8214 {
8215 if(auto* trig = get_combo_trigger(ri->combotrigref))
8216 {
8217 ret = trig->spawnitem * 10000;
8218 }
8219 else ret = -10000;
8220 break;
8221 }
8222 case CMBTRIGLSTATE:
8223 {
8224 if(auto* trig = get_combo_trigger(ri->combotrigref))
8225 {
8226 ret = trig->trig_lstate * 10000;
8227 }
8228 else ret = -10000;
8229 break;
8230 }
8231 case CMBTRIGGSTATE:
8232 {
8233 if(auto* trig = get_combo_trigger(ri->combotrigref))
8234 {
8235 ret = trig->trig_gstate * 10000;
8236 }
8237 else ret = -10000;
8238 break;
8239 }
8240 case CMBTRIGGTIMER:
8241 {
8242 if(auto* trig = get_combo_trigger(ri->combotrigref))
8243 {
8244 ret = trig->trig_statetime * 10000;
8245 }
8246 else ret = -10000;
8247 break;
8248 }
8249 case CMBTRIGGENSCRIPT:
8250 {
8251 if(auto* trig = get_combo_trigger(ri->combotrigref))
8252 {
8253 ret = trig->trig_genscr * 10000;
8254 }
8255 else ret = -10000;
8256 break;
8257 }
8258 case CMBTRIGGROUP:
8259 {
8260 if(auto* trig = get_combo_trigger(ri->combotrigref))
8261 {
8262 ret = trig->trig_group * 10000;
8263 }
8264 else ret = -10000;
8265 break;
8266 }
8267 case CMBTRIGGROUPVAL:
8268 {
8269 if(auto* trig = get_combo_trigger(ri->combotrigref))
8270 {
8271 ret = trig->trig_group_val * 10000;
8272 }
8273 else ret = -10000;
8274 break;
8275 }
8276 case CMBTRIGLITEMS:
8277 {
8278 if(auto* trig = get_combo_trigger(ri->combotrigref))
8279 {
8280 ret = trig->trig_levelitems * 10000;
8281 }
8282 else ret = -10000;
8283 break;
8284 }
8285 case CMBTRIGDMAPLVL:
8286 {
8287 if(auto* trig = get_combo_trigger(ri->combotrigref))
8288 {
8289 ret = trig->trigdmlevel * 10000;
8290 }
8291 else ret = -10000;
8292 break;
8293 }
8294 case CMBTRIGTINTR:
8295 {
8296 if(auto* trig = get_combo_trigger(ri->combotrigref))
8297 {
8298 ret = trig->trigtint[0] * 10000;
8299 }
8300 else ret = -10000;
8301 break;
8302 }
8303 case CMBTRIGTINTG:
8304 {
8305 if(auto* trig = get_combo_trigger(ri->combotrigref))
8306 {
8307 ret = trig->trigtint[1] * 10000;
8308 }
8309 else ret = -10000;
8310 break;
8311 }
8312 case CMBTRIGTINTB:
8313 {
8314 if(auto* trig = get_combo_trigger(ri->combotrigref))
8315 {
8316 ret = trig->trigtint[2] * 10000;
8317 }
8318 else ret = -10000;
8319 break;
8320 }
8321 case CMBTRIGLVLPAL:
8322 {
8323 if(auto* trig = get_combo_trigger(ri->combotrigref))
8324 {
8325 ret = trig->triglvlpalette * 10000;
8326 }
8327 else ret = -10000;
8328 break;
8329 }
8330 case CMBTRIGBOSSPAL:
8331 {
8332 if(auto* trig = get_combo_trigger(ri->combotrigref))
8333 {
8334 ret = trig->trigbosspalette * 10000;
8335 }
8336 else ret = -10000;
8337 break;
8338 }
8339 case CMBTRIGQUAKETIME:
8340 {
8341 if(auto* trig = get_combo_trigger(ri->combotrigref))
8342 {
8343 ret = trig->trigquaketime * 10000;
8344 }
8345 else ret = -10000;
8346 break;
8347 }
8348 case CMBTRIGWAVYTIME:
8349 {
8350 if(auto* trig = get_combo_trigger(ri->combotrigref))
8351 {
8352 ret = trig->trigwavytime * 10000;
8353 }
8354 else ret = -10000;
8355 break;
8356 }
8357 case CMBTRIGSWORDJINX:
8358 {
8359 if(auto* trig = get_combo_trigger(ri->combotrigref))
8360 {
8361 ret = trig->trig_swjinxtime * 10000;
8362 }
8363 else ret = -10000;
8364 break;
8365 }
8366 case CMBTRIGITEMJINX:
8367 {
8368 if(auto* trig = get_combo_trigger(ri->combotrigref))
8369 {
8370 ret = trig->trig_itmjinxtime * 10000;
8371 }
8372 else ret = -10000;
8373 break;
8374 }
8375 case CMBTRIGSHIELDJINX:
8376 {
8377 if(auto* trig = get_combo_trigger(ri->combotrigref))
8378 {
8379 ret = trig->trig_shieldjinxtime * 10000;
8380 }
8381 else ret = -10000;
8382 break;
8383 }
8384 case CMBTRIGSTUN:
8385 {
8386 if(auto* trig = get_combo_trigger(ri->combotrigref))
8387 {
8388 ret = trig->trig_stuntime * 10000;
8389 }
8390 else ret = -10000;
8391 break;
8392 }
8393 case CMBTRIGBUNNY:
8394 {
8395 if(auto* trig = get_combo_trigger(ri->combotrigref))
8396 {
8397 ret = trig->trig_bunnytime * 10000;
8398 }
8399 else ret = -10000;
8400 break;
8401 }
8402 case CMBTRIGPUSHTIME:
8403 {
8404 if(auto* trig = get_combo_trigger(ri->combotrigref))
8405 {
8406 ret = trig->trig_pushtime * 10000;
8407 }
8408 else ret = -10000;
8409 break;
8410 }
8411 case CMBTRIGGERPROMPTCID:
8412 {
8413 if(auto* trig = get_combo_trigger(ri->combotrigref))
8414 ret = trig->prompt_cid * 10000;
8415 else ret = -10000;
8416 break;
8417 }
8418 case CMBTRIGGERPROMPTCS:
8419 {
8420 if(auto* trig = get_combo_trigger(ri->combotrigref))
8421 ret = trig->prompt_cs * 10000;
8422 else ret = -10000;
8423 break;
8424 }
8425 case CMBTRIGGERFAILPROMPTCID:
8426 {
8427 if(auto* trig = get_combo_trigger(ri->combotrigref))
8428 ret = trig->fail_prompt_cid * 10000;
8429 else ret = -10000;
8430 break;
8431 }
8432 case CMBTRIGGERFAILPROMPTCS:
8433 {
8434 if(auto* trig = get_combo_trigger(ri->combotrigref))
8435 ret = trig->fail_prompt_cs * 10000;
8436 else ret = -10000;
8437 break;
8438 }
8439 case CMBTRIGGERPROMPTX:
8440 {
8441 if(auto* trig = get_combo_trigger(ri->combotrigref))
8442 ret = trig->prompt_x * 10000;
8443 else ret = -10000;
8444 break;
8445 }
8446 case CMBTRIGGERPROMPTY:
8447 {
8448 if(auto* trig = get_combo_trigger(ri->combotrigref))
8449 ret = trig->prompt_y * 10000;
8450 else ret = -10000;
8451 break;
8452 }
8453 case CMBTRIGGERTRIGSTR:
8454 {
8455 if(auto* trig = get_combo_trigger(ri->combotrigref))
8456 ret = trig->trig_msgstr * 10000;
8457 else ret = -10000;
8458 break;
8459 }
8460 case CMBTRIGGERFAILSTR:
8461 {
8462 if(auto* trig = get_combo_trigger(ri->combotrigref))
8463 ret = trig->fail_msgstr * 10000;
8464 else ret = -10000;
8465 break;
8466 }
8467 case CMBTRIGGERPLAYERBOUNCE:
8468 {
8469 if(auto* trig = get_combo_trigger(ri->combotrigref))
8470 ret = trig->player_bounce;
8471 else ret = -10000;
8472 break;
8473 }
8474 case CMBTRIGGERREQPLAYERZ:
8475 {
8476 if(auto* trig = get_combo_trigger(ri->combotrigref))
8477 ret = trig->req_player_z;
8478 else ret = -10000;
8479 break;
8480 }
8481 case CMBTRIGGERDESTHEROX:
8482 {
8483 if(auto* trig = get_combo_trigger(ri->combotrigref))
8484 ret = trig->dest_player_x;
8485 else ret = -10000;
8486 break;
8487 }
8488 case CMBTRIGGERDESTHEROY:
8489 {
8490 if(auto* trig = get_combo_trigger(ri->combotrigref))
8491 ret = trig->dest_player_y;
8492 else ret = -10000;
8493 break;
8494 }
8495 case CMBTRIGGERDESTHEROZ:
8496 {
8497 if(auto* trig = get_combo_trigger(ri->combotrigref))
8498 ret = trig->dest_player_z;
8499 else ret = -10000;
8500 break;
8501 }
8502 case CMBTRIGGERREQPLAYERJUMP:
8503 {
8504 if(auto* trig = get_combo_trigger(ri->combotrigref))
8505 ret = trig->req_player_jump;
8506 else ret = -10000;
8507 break;
8508 }
8509 case CMBTRIGGERREQPLAYERX:
8510 {
8511 if(auto* trig = get_combo_trigger(ri->combotrigref))
8512 ret = trig->req_player_x;
8513 else ret = -10000;
8514 break;
8515 }
8516 case CMBTRIGGERREQPLAYERY:
8517 {
8518 if(auto* trig = get_combo_trigger(ri->combotrigref))
8519 ret = trig->req_player_y;
8520 else ret = -10000;
8521 break;
8522 }
8523 ///----------------------------------------------------------------------------------------------------//
8524 //npcdata nd-> variables
8525
8526 //npcdata nd->member variable
8527 #define GET_NPCDATA_VAR_INT32(member, str) \
8528 { \
8529 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
8530 { \
8531 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", str, (ri->npcdataref*10000)); \
8532 ret = -10000; \
8533 } \
8534 else \
8535 { \
8536 ret = (guysbuf[ri->npcdataref].member *10000); \
8537 } \
8538 } \
8539
8540 #define GET_NPCDATA_VAR_BYTE(member, str) \
8541 { \
8542 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
8543 { \
8544 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", str, (ri->npcdataref*10000)); \
8545 ret = -10000; \
8546 } \
8547 else \
8548 { \
8549 ret = (guysbuf[ri->npcdataref].member *10000); \
8550 } \
8551 } \
8552
8553 #define GET_NPCDATA_VAR_INT16(member, str) \
8554 { \
8555 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
8556 { \
8557 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", str, (ri->npcdataref*10000)); \
8558 ret = -10000; \
8559 } \
8560 else \
8561 { \
8562 ret = (guysbuf[ri->npcdataref].member *10000); \
8563 } \
8564 } \
8565
8566 #define GET_NPCDATA_FLAG(member, str, indexbound) \
8567 { \
8568 int32_t flag = (value/10000); \
8569 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
8570 { \
8571 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", str, (ri->npcdataref*10000)); \
8572 } \
8573 else \
8574 { \
8575 ret = (guysbuf[ID].member&flag) ? 10000 : 0); \
8576 } \
8577 } \
8578
8579 // These are for compat only, though seemingly no quests even use these.
8580 case NPCDATAFLAGS1:
8581 {
8582 if( (unsigned) ri->npcdataref > (MAXNPCS-1) )
8583 {
8584 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", "Flags (deprecated)", (ri->npcdataref*10000));
8585 ret = -10000;
8586 }
8587 else
8588 {
8589 uint32_t value = guysbuf[ri->npcdataref].flags & 0xFFFFFFFFLL;
8590 ret = value * 10000;
8591 }
8592 }
8593 break;
8594 case NPCDATAFLAGS2:
8595 {
8596 if( (unsigned) ri->npcdataref > (MAXNPCS-1) )
8597 {
8598 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", "Flags2 (deprecated)", (ri->npcdataref*10000));
8599 ret = -10000;
8600 }
8601 else
8602 {
8603 uint32_t value = (guysbuf[ri->npcdataref].flags >> 32) & 0xFFFFFFFFLL;
8604 ret = value * 10000;
8605 }
8606 }
8607 break;
8608
8609 case NPCDATATILE: GET_NPCDATA_VAR_BYTE(tile, "Tile"); break;
8610 case NPCDATAWIDTH: GET_NPCDATA_VAR_BYTE(width, "Width"); break;
8611 case NPCDATAHEIGHT: GET_NPCDATA_VAR_BYTE(height, "Height"); break;
8612 case NPCDATASTILE: GET_NPCDATA_VAR_BYTE(s_tile, "STile"); break;
8613 case NPCDATASWIDTH: GET_NPCDATA_VAR_BYTE(s_width, "SWidth"); break;
8614 case NPCDATASHEIGHT: GET_NPCDATA_VAR_BYTE(s_height, "SHeight"); break;
8615
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3182 times.
3182 case NPCDATAETILE: GET_NPCDATA_VAR_INT32(e_tile, "ExTile"); break;
8616 case NPCDATAEWIDTH: GET_NPCDATA_VAR_BYTE(e_width, "ExWidth"); break;
8617 case NPCDATAEHEIGHT: GET_NPCDATA_VAR_BYTE(e_height, "ExHeight"); break;
8618 case NPCDATAHP: GET_NPCDATA_VAR_INT16(hp, "HP"); break;
8619 case NPCDATAFAMILY: GET_NPCDATA_VAR_INT16(family, "Family"); break;
8620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3182 times.
3182 case NPCDATACSET: GET_NPCDATA_VAR_INT16(cset, "CSet"); break;
8621 case NPCDATAANIM: GET_NPCDATA_VAR_INT16(anim, "Anim"); break;
8622 case NPCDATAEANIM: GET_NPCDATA_VAR_INT16(e_anim, "ExAnim"); break;
8623 case NPCDATAFRAMERATE: GET_NPCDATA_VAR_INT16(frate, "Framerate"); break;
8624 case NPCDATAEFRAMERATE: GET_NPCDATA_VAR_INT16(e_frate, "ExFramerate"); break;
8625 case NPCDATATOUCHDAMAGE: GET_NPCDATA_VAR_INT16(dp, "TouchDamage"); break;
8626 case NPCDATAWEAPONDAMAGE: GET_NPCDATA_VAR_INT16(wdp, "WeaponDamage"); break;
8627 case NPCDATAWEAPON: GET_NPCDATA_VAR_INT16(weapon, "Weapon"); break;
8628 case NPCDATARANDOM: GET_NPCDATA_VAR_INT16(rate, "Random"); break;
8629 case NPCDATAHALT: GET_NPCDATA_VAR_INT16(hrate, "Haltrate"); break;
8630 case NPCDATASTEP: GET_NPCDATA_VAR_INT16(step, "Step"); break;
8631 case NPCDATAHOMING: GET_NPCDATA_VAR_INT16(homing, "Homing"); break;
8632 case NPCDATAHUNGER: GET_NPCDATA_VAR_INT16(grumble, "Hunger"); break;
8633 case NPCDATADROPSET: GET_NPCDATA_VAR_INT16(item_set, "Dropset"); break;
8634 case NPCDATABGSFX: GET_NPCDATA_VAR_INT16(bgsfx, "BGSFX"); break;
8635 case NPCDATADEATHSFX: GET_NPCDATA_VAR_BYTE(deadsfx, "DeathSFX"); break;
8636
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 case NPCDATAHITSFX: GET_NPCDATA_VAR_BYTE(hitsfx, "HitSFX"); break;
8637 case NPCDATAXOFS: GET_NPCDATA_VAR_INT32(xofs, "DrawXOffset"); break;
8638 case NPCDATAYOFS: GET_NPCDATA_VAR_INT32(yofs, "DrawYOffset"); break;
8639 case NPCDATAZOFS: GET_NPCDATA_VAR_INT32(zofs, "DrawZOffset"); break;
8640 case NPCDATAHXOFS: GET_NPCDATA_VAR_INT32(hxofs, "HitXOffset"); break;
8641 case NPCDATAHYOFS: GET_NPCDATA_VAR_INT32(hyofs, "HitYOffset"); break;
8642 case NPCDATAHITWIDTH: GET_NPCDATA_VAR_INT32(hxsz, "HitWidth"); break;
8643 case NPCDATAHITHEIGHT: GET_NPCDATA_VAR_INT32(hysz, "HitHeight"); break;
8644 case NPCDATAHITZ: GET_NPCDATA_VAR_INT32(hzsz, "HitZHeight"); break;
8645 case NPCDATASCRIPT: GET_NPCDATA_VAR_INT32(script, "Script"); break;
8646 case NPCDATATILEWIDTH: GET_NPCDATA_VAR_INT32(txsz, "TileWidth"); break;
8647 case NPCDATATILEHEIGHT: GET_NPCDATA_VAR_INT32(tysz, "TileHeight"); break;
8648 case NPCDATAWPNSPRITE: GET_NPCDATA_VAR_INT32(wpnsprite, "WeaponSprite"); break;
8649 case NPCDATAWEAPONSCRIPT: GET_NPCDATA_VAR_INT32(weaponscript, "WeaponScript"); break;
8650 case NPCDATASIZEFLAG: GET_NPCDATA_VAR_INT32(SIZEflags, "SizeFlags"); break;
8651
8652 case NPCDATAFROZENTILE: GET_NPCDATA_VAR_INT32(frozentile, "FrozenTile"); break;
8653 case NPCDATAFROZENCSET: GET_NPCDATA_VAR_INT32(frozencset, "FrozenCSet"); break;
8654 case NPCDATAFIRESFX: GET_NPCDATA_VAR_BYTE(firesfx, "WeaponSFX"); break;
8655
8656 case NPCDSHADOWSPR:
8657 {
8658 if(ri->npcdataref > (MAXNPCS-1) )
8659 {
8660 Z_scripterrlog("Invalid NPC ID passed to npcdata->ShadowSprite: %d\n", (ri->npcdataref*10000));
8661 ret = -10000;
8662 }
8663 else
8664 {
8665 ret = guysbuf[ri->npcdataref].spr_shadow * 10000;
8666 }
8667 break;
8668 }
8669 case NPCDSPAWNSPR:
8670 {
8671 if(ri->npcdataref > (MAXNPCS-1) )
8672 {
8673 Z_scripterrlog("Invalid NPC ID passed to npcdata->SpawnSprite: %d\n", (ri->npcdataref*10000));
8674 ret = -10000;
8675 }
8676 else
8677 {
8678 ret = guysbuf[ri->npcdataref].spr_spawn * 10000;
8679 }
8680 break;
8681 }
8682 case NPCDDEATHSPR:
8683 {
8684 if(ri->npcdataref > (MAXNPCS-1) )
8685 {
8686 Z_scripterrlog("Invalid NPC ID passed to npcdata->DeathSprite: %d\n", (ri->npcdataref*10000));
8687 ret = -10000;
8688 }
8689 else
8690 {
8691 ret = guysbuf[ri->npcdataref].spr_death * 10000;
8692 }
8693 break;
8694 }
8695
8696 case NPCMATCHINITDLABEL: //Same form as SetScreenD()
8697 //bool npcdata->MatchInitDLabel("label", d)
8698 {
8699
8700 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
8701 {
8702 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", (ri->npcdataref*10000), "MatchInitDLabel()");
8703 ret = 0;
8704 break;
8705 }
8706
8707 int32_t arrayptr = get_register(sarg1);
8708 int32_t init_d_index = get_register(sarg2) / 10000;
8709
8710 string name;
8711 ArrayH::getString(arrayptr, name, 256); // What's the limit on name length?
8712
8713 bool match = (!( strcmp(name.c_str(), guysbuf[ri->npcdataref].initD_label[init_d_index] )));
8714
8715 ret = ( match ? 10000 : 0 );
8716 break;
8717 }
8718
8719 ///----------------------------------------------------------------------------------------------------//
8720 //Dropset Variables
8721
8722 case DROPSETNULLCHANCE:
8723 {
8724 if(ri->dropsetref > MAXITEMDROPSETS)
8725 {
8726 Z_scripterrlog("Invalid dropset pointer %d\n", ri->dropsetref);
8727 ret = -10000;
8728 break;
8729 }
8730 ret = item_drop_sets[ri->dropsetref].chance[0] * 10000;
8731 break;
8732 }
8733 case DROPSETCHOOSE:
8734 {
8735
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(ri->dropsetref > MAXITEMDROPSETS)
8736 {
8737 Z_scripterrlog("Invalid dropset pointer %d\n", ri->dropsetref);
8738 ret = -10000;
8739 break;
8740 }
8741 10 ret = select_dropitem(ri->dropsetref) * 10000;
8742 10 break;
8743 }
8744
8745 ///----------------------------------------------------------------------------------------------------//
8746 //Audio Variables
8747
8748 case AUDIOPAN:
8749 {
8750 ret = FFScript::do_getSFX_pan() * 10000;
8751 break;
8752 }
8753
8754 ///----------------------------------------------------------------------------------------------------//
8755 //Graphics->
8756
8757 case NUMDRAWS:
8758 ret = script_drawing_commands.Count() * 10000;
8759 //ret = FFCore.numscriptdraws * 10000; // This isn't updated until end of frame, making it useless!
8760 break;
8761
8762 case MAXDRAWS:
8763 ret = MAX_SCRIPT_DRAWING_COMMANDS * 10000;
8764 break;
8765
8766 case BITMAPWIDTH:
8767 {
8768
2/4
✓ Branch 0 taken 3453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3453 times.
✗ Branch 3 not taken.
3453 if (auto bmp = user_bitmaps.check(ri->bitmapref); bmp && bmp->u_bmp)
8769 {
8770 3453 ret = bmp->width * 10000;
8771 3453 }
8772 else
8773 {
8774 ret = -10000;
8775 }
8776 3453 break;
8777 }
8778
8779 case BITMAPHEIGHT:
8780 {
8781 if (auto bmp = user_bitmaps.check(ri->bitmapref); bmp && bmp->u_bmp)
8782 {
8783 ret = bmp->height * 10000;
8784 }
8785 else
8786 {
8787 ret = -10000;
8788 }
8789 break;
8790 }
8791 ///----------------------------------------------------------------------------------------------------//
8792 //File->
8793 case FILEPOS:
8794 {
8795 if(user_file* f = checkFile(ri->fileref, true))
8796 {
8797 ret = ftell(f->file); //NOT *10000 -V
8798 }
8799 else ret = -10000L;
8800 break;
8801 }
8802 case FILEEOF:
8803 {
8804 if(user_file* f = checkFile(ri->fileref, true))
8805 {
8806 ret = feof(f->file) ? 10000L : 0L; //Boolean
8807 }
8808 else ret = -10000L;
8809 break;
8810 }
8811 case FILEERR:
8812 {
8813 if(user_file* f = checkFile(ri->fileref, true))
8814 {
8815 ret = ferror(f->file) * 10000L;
8816 }
8817 else ret = -10000L;
8818 break;
8819 }
8820
8821 ///----------------------------------------------------------------------------------------------------//
8822 //Directory->
8823 case DIRECTORYSIZE:
8824 {
8825 if(user_dir* dr = checkDir(ri->directoryref, true))
8826 {
8827 ret = dr->size() * 10000L;
8828 }
8829 else ret = -10000L;
8830 break;
8831 }
8832
8833 ///----------------------------------------------------------------------------------------------------//
8834 //Stack->
8835 case STACKSIZE:
8836 {
8837 if(user_stack* st = checkStack(ri->stackref, true))
8838 {
8839 ret = st->size(); //NOT *10000
8840 }
8841 else ret = -10000L;
8842 break;
8843 }
8844 case STACKFULL:
8845 {
8846 if(user_stack* st = checkStack(ri->stackref, true))
8847 {
8848 ret = st->full() ? 10000L : 0L;
8849 }
8850 else ret = -10000L;
8851 break;
8852 }
8853
8854 ///----------------------------------------------------------------------------------------------------//
8855 //Misc./Internal
8856 case REFFFC:
8857
2/2
✓ Branch 0 taken 730 times.
✓ Branch 1 taken 25916 times.
26646 ret = ZScriptVersion::ffcRefIsSpriteId() ? ri->ffcref : ri->ffcref * 10000;
8858 26646 break;
8859
8860 case REFITEM:
8861 608463 ret = ri->itemref;
8862 608463 break;
8863
8864 case REFITEMCLASS:
8865 5613429 ret = ri->idata;
8866 5613429 break;
8867
8868 case REFLWPN:
8869 1561195 ret = ri->lwpn;
8870 1561195 break;
8871
8872 case REFEWPN:
8873 4923553 ret = ri->ewpn;
8874 4923553 break;
8875
8876 case REFNPC:
8877 27873688 ret = ri->guyref;
8878 27873688 break;
8879
8880 case REFSPRITE:
8881 ret = ri->spriteref;
8882 break;
8883
8884 case REFMAPDATA: ret = ri->mapsref; break;
8885 20 case REFSCREENDATA: ret = ri->screenref; break;
8886 215684 case REFCOMBODATA: ret = ri->combosref; break;
8887 case REFCOMBOTRIGGER: ret = ri->combotrigref; break;
8888 16 case REFSPRITEDATA: ret = ri->spritedataref; break;
8889 10 case REFBITMAP: ret = ri->bitmapref; break;
8890 1 case REFNPCCLASS: ret = ri->npcdataref; break;
8891
8892
8893 72922 case REFDMAPDATA: ret = ri->dmapsref; break;
8894 case REFSHOPDATA: ret = ri->shopsref; break;
8895 24 case REFMSGDATA: ret = ri->zmsgref; break;
8896
8897 10 case REFDROPS: ret = ri->dropsetref; break;
8898 case REFBOTTLETYPE: ret = ri->bottletyperef; break;
8899 case REFBOTTLESHOP: ret = ri->bottleshopref; break;
8900 137701 case REFGENERICDATA: ret = ri->genericdataref; break;
8901 case REFFILE: ret = ri->fileref; break;
8902 case REFDIRECTORY: ret = ri->directoryref; break;
8903 case REFSTACK: ret = ri->stackref; break;
8904 36 case REFSUBSCREEN: ret = ri->subdataref; break;
8905 case REFSUBSCREENPAGE: ret = ri->subpageref; break;
8906 case REFSUBSCREENWIDG: ret = ri->subwidgref; break;
8907 case REFRNG: ret = ri->rngref; break;
8908 case REFWEBSOCKET: ret = ri->websocketref; break;
8909 6280 case CLASS_THISKEY: ret = ri->thiskey; break;
8910 1113 case CLASS_THISKEY2: ret = ri->thiskey2; break;
8911 case REFPALDATA: ret = ri->paldataref; break;
8912
8913
8914 case SP:
8915 8 ret = ri->sp * 10000;
8916 8 break;
8917 case SP2:
8918 63 ret = ri->sp;
8919 63 break;
8920
8921 case PC:
8922 ret = ri->pc;
8923 break;
8924
8925 case SWITCHKEY:
8926 5 ret = ri->switchkey;
8927 5 break;
8928
8929 case SCRIPTRAM:
8930 case GLOBALRAM:
8931 1125663332 ret = ArrayH::getElement(ri->d[rINDEX], ri->d[rINDEX2] / 10000);
8932 1125663332 break;
8933
8934 case SCRIPTRAMD:
8935 case GLOBALRAMD:
8936 ret = ArrayH::getElement(ri->d[rINDEX], 0);
8937 break;
8938
8939 case GDD: // Unused, remove?
8940 ret = read_array(game->global_d, ri->d[rINDEX] / 10000);
8941 break;
8942
8943 ///----------------------------------------------------------------------------------------------------//
8944
8945 case GENDATARUNNING:
8946 {
8947 5487 ret = 0;
8948
1/2
✓ Branch 0 taken 5487 times.
✗ Branch 1 not taken.
5487 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
8949 {
8950 5487 ret = scr->doscript() ? 10000L : 0L;
8951 5487 }
8952 5487 break;
8953 }
8954 case GENDATASIZE:
8955 {
8956 ret = 0;
8957 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
8958 {
8959 ret = scr->dataSize()*10000;
8960 }
8961 break;
8962 }
8963
8964 ///----------------------------------------------------------------------------------------------------//
8965
8966 case PORTALX:
8967 {
8968 ret = -10000;
8969 if(portal* p = checkPortal(ri->portalref))
8970 ret = p->x.getZLong();
8971 break;
8972 }
8973 case PORTALY:
8974 {
8975 ret = -10000;
8976 if(portal* p = checkPortal(ri->portalref))
8977 ret = p->y.getZLong();
8978 break;
8979 }
8980 case PORTALDMAP:
8981 {
8982 ret = -10000;
8983 if(portal* p = checkPortal(ri->portalref))
8984 ret = p->destdmap*10000;
8985 break;
8986 }
8987 case PORTALSCREEN:
8988 {
8989 ret = -10000;
8990 if(portal* p = checkPortal(ri->portalref))
8991 ret = p->destscr*10000;
8992 break;
8993 }
8994 case PORTALACLK:
8995 {
8996 ret = -10000;
8997 if(portal* p = checkPortal(ri->portalref))
8998 ret = p->aclk*10000;
8999 break;
9000 }
9001 case PORTALAFRM:
9002 {
9003 ret = -10000;
9004 if(portal* p = checkPortal(ri->portalref))
9005 ret = p->aframe*10000;
9006 break;
9007 }
9008 case PORTALOTILE:
9009 {
9010 ret = -10000;
9011 if(portal* p = checkPortal(ri->portalref))
9012 ret = p->o_tile*10000;
9013 break;
9014 }
9015 case PORTALASPD:
9016 {
9017 ret = -10000;
9018 if(portal* p = checkPortal(ri->portalref))
9019 ret = p->aspd*10000;
9020 break;
9021 }
9022 case PORTALFRAMES:
9023 {
9024 ret = -10000;
9025 if(portal* p = checkPortal(ri->portalref))
9026 ret = p->frames*10000;
9027 break;
9028 }
9029 case PORTALSAVED:
9030 {
9031 ret = 0;
9032 if(portal* p = checkPortal(ri->portalref))
9033 ret = p->saved_data;
9034 break;
9035 }
9036 case PORTALCLOSEDIS:
9037 {
9038 ret = 0;
9039 if(portal* p = checkPortal(ri->portalref))
9040 ret = p->prox_active ? 0 : 10000; //Inverted
9041 break;
9042 }
9043 case REFPORTAL:
9044 {
9045 ret = ri->portalref;
9046 break;
9047 }
9048 case REFSAVPORTAL:
9049 {
9050 ret = ri->saveportalref;
9051 break;
9052 }
9053 case PORTALWARPSFX:
9054 {
9055 ret = 0;
9056 if(portal* p = checkPortal(ri->portalref))
9057 ret = p->wsfx ? 0 : 10000;
9058 break;
9059 }
9060 case PORTALWARPVFX:
9061 {
9062 ret = 0;
9063 if(portal* p = checkPortal(ri->portalref))
9064 ret = p->weffect ? 0 : 10000;
9065 break;
9066 }
9067 case SAVEDPORTALX:
9068 {
9069 ret = -10000;
9070 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9071 ret = p->x;
9072 break;
9073 }
9074 case SAVEDPORTALY:
9075 {
9076 ret = -10000;
9077 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9078 ret = p->y;
9079 break;
9080 }
9081 case SAVEDPORTALSRCDMAP:
9082 {
9083 ret = -10000;
9084 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9085 ret = p->srcdmap * 10000;
9086 break;
9087 }
9088 case SAVEDPORTALDESTDMAP:
9089 {
9090 ret = -10000;
9091 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9092 ret = p->destdmap * 10000;
9093 break;
9094 }
9095 case SAVEDPORTALSRCSCREEN:
9096 {
9097 ret = -10000;
9098 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9099 ret = p->srcscr * 10000;
9100 break;
9101 }
9102 case SAVEDPORTALDSTSCREEN:
9103 {
9104 ret = -10000;
9105 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9106 ret = p->destscr * 10000;
9107 break;
9108 }
9109 case SAVEDPORTALWARPSFX:
9110 {
9111 ret = -10000;
9112 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9113 ret = p->sfx * 10000;
9114 break;
9115 }
9116 case SAVEDPORTALWARPVFX:
9117 {
9118 ret = -10000;
9119 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9120 ret = p->warpfx * 10000;
9121 break;
9122 }
9123 case SAVEDPORTALSPRITE:
9124 {
9125 ret = -10000;
9126 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9127 ret = p->spr * 10000;
9128 break;
9129 }
9130 case SAVEDPORTALPORTAL:
9131 {
9132 ret = 0;
9133 if(savedportal* p = checkSavedPortal(ri->saveportalref))
9134 ret = getPortalFromSaved(p);
9135 break;
9136 }
9137 case PORTALCOUNT:
9138 {
9139 ret = portals.Count()*10000;
9140 break;
9141 }
9142 case SAVEDPORTALCOUNT:
9143 {
9144 ret = game->user_portals.size()*10000;
9145 break;
9146 }
9147
9148 case GAMEASUBOPEN:
9149 {
9150 ret = subscreen_open ? 10000 : 0;
9151 break;
9152 }
9153 case GAMEASUBYOFF:
9154 {
9155 14124 ret = active_sub_yoff*10000;
9156 14124 break;
9157 }
9158 case GAMENUMASUB:
9159 {
9160 ret = subscreens_active.size()*10000;
9161 break;
9162 }
9163 case GAMENUMPSUB:
9164 {
9165 ret = subscreens_passive.size()*10000;
9166 break;
9167 }
9168 case GAMENUMOSUB:
9169 {
9170 ret = subscreens_overlay.size()*10000;
9171 break;
9172 }
9173
9174 ///----------------------------------------------------------------------------------------------------//
9175
9176 case SUBDATACURPG:
9177 {
9178
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54674 times.
54674 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
9179
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54674 times.
109348 if(sub->sub_type == sstACTIVE)
9180 54674 ret = 10000*sub->curpage;
9181 54674 break;
9182 }
9183 case SUBDATANUMPG:
9184 {
9185
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
9186 {
9187
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(sub->sub_type == sstACTIVE)
9188 11 ret = 10000*sub->pages.size();
9189 else ret = 10000;
9190 11 }
9191 11 break;
9192 }
9193 case SUBDATATYPE:
9194 {
9195 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
9196 ret = sub->sub_type*10000;
9197 break;
9198 }
9199
9200 ///---- ACTIVE SUBSCREENS ONLY
9201 case SUBDATACURSORPOS:
9202 {
9203 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9204 {
9205 SubscrPage& pg = sub->cur_page();
9206 ret = pg.cursor_pos * 10000;
9207 }
9208 break;
9209 }
9210 case SUBDATASCRIPT:
9211 {
9212 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9213 ret = sub->script * 10000;
9214 break;
9215 }
9216 case SUBDATATRANSLEFTTY:
9217 {
9218 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9219 {
9220 auto& trans = sub->trans_left;
9221 ret = trans.type * 10000;
9222 }
9223 break;
9224 }
9225 case SUBDATATRANSLEFTSFX:
9226 {
9227 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9228 {
9229 auto& trans = sub->trans_left;
9230 ret = trans.tr_sfx * 10000;
9231 }
9232 break;
9233 }
9234 case SUBDATATRANSRIGHTTY:
9235 {
9236 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9237 {
9238 auto& trans = sub->trans_right;
9239 ret = trans.type * 10000;
9240 }
9241 break;
9242 }
9243 case SUBDATATRANSRIGHTSFX:
9244 {
9245 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9246 {
9247 auto& trans = sub->trans_right;
9248 ret = trans.tr_sfx * 10000;
9249 }
9250 break;
9251 }
9252 case SUBDATASELECTORDSTX:
9253 {
9254 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9255 ret = sub->selector_setting.x * 10000;
9256 break;
9257 }
9258 case SUBDATASELECTORDSTY:
9259 {
9260 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9261 ret = sub->selector_setting.y * 10000;
9262 break;
9263 }
9264 case SUBDATASELECTORDSTW:
9265 {
9266 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9267 ret = sub->selector_setting.w * 10000;
9268 break;
9269 }
9270 case SUBDATASELECTORDSTH:
9271 {
9272 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9273 ret = sub->selector_setting.h * 10000;
9274 break;
9275 }
9276 ///---- CURRENTLY OPEN ACTIVE SUBSCREEN ONLY
9277 case SUBDATATRANSCLK:
9278 {
9279 5031 ret = -10000;
9280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5031 times.
5031 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9281 {
9282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5031 times.
5031 if(sub != new_subscreen_active)
9283 Z_scripterrlog("'subscreendata->TransClock' is only"
9284 " valid for the current active subscreen!\n");
9285
3/4
✓ Branch 0 taken 5031 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4855 times.
✓ Branch 3 taken 176 times.
5031 else if(subscreen_open && subscr_pg_animating)
9286 176 ret = subscr_pg_clk*10000;
9287 5031 }
9288 5031 break;
9289 }
9290 case SUBDATATRANSTY:
9291 {
9292 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9293 {
9294 auto& trans = subscr_pg_transition;
9295 if(sub != new_subscreen_active)
9296 Z_scripterrlog("'subscreendata->TransType' is only"
9297 " valid for the current active subscreen!\n");
9298 else if(subscreen_open)
9299 ret = trans.type*10000;
9300 }
9301 break;
9302 }
9303 case SUBDATATRANSFROMPG:
9304 {
9305 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9306 {
9307 if(sub != new_subscreen_active)
9308 Z_scripterrlog("'subscreendata->TransFromPage' is only"
9309 " valid for the current active subscreen!\n");
9310 else if(subscreen_open)
9311 ret = subscr_pg_from*10000;
9312 }
9313 break;
9314 }
9315 case SUBDATATRANSTOPG:
9316 {
9317 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
9318 {
9319 if(sub != new_subscreen_active)
9320 Z_scripterrlog("'subscreendata->TransToPage' is only"
9321 " valid for the current active subscreen!\n");
9322 else if(subscreen_open)
9323 ret = subscr_pg_to*10000;
9324 }
9325 break;
9326 }
9327
9328 ///----------------------------------------------------------------------------------------------------//
9329 case SUBPGINDEX:
9330 {
9331 if(SubscrPage* pg = checkSubPage(ri->subpageref))
9332 ret = pg->getIndex() * 10000;
9333 break;
9334 }
9335 case SUBPGNUMWIDG:
9336 {
9337
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1005 times.
1005 if(SubscrPage* pg = checkSubPage(ri->subpageref))
9338 1005 ret = pg->size() * 10000;
9339 1005 break;
9340 }
9341 case SUBPGSUBDATA:
9342 {
9343 if(SubscrPage* pg = checkSubPage(ri->subpageref))
9344 {
9345 auto [sub,ty,_pgid,_ind] = from_subref(ri->subpageref);
9346 ret = get_subref(sub,ty,0,0);
9347 }
9348 break;
9349 }
9350 case SUBPGCURSORPOS:
9351 {
9352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17326 times.
17326 if(SubscrPage* pg = checkSubPage(ri->subpageref))
9353 17326 ret = pg->cursor_pos * 10000;
9354 17326 break;
9355 }
9356 ///----------------------------------------------------------------------------------------------------//
9357 ///---- ANY WIDGET TYPE
9358 case SUBWIDGTYPE:
9359 {
9360
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6024 times.
6024 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9361 6024 ret = 10000*widg->getType();
9362 6024 break;
9363 }
9364 case SUBWIDGINDEX:
9365 {
9366 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9367 {
9368 auto [_sub,_ty,_pgid,ind] = from_subref(ri->subwidgref);
9369 ret = 10000*ind;
9370 }
9371 break;
9372 }
9373 case SUBWIDGDISPITM:
9374 {
9375
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4206 times.
4206 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9376 {
9377 4206 ret = 10000*widg->getDisplayItem();
9378 4206 }
9379 4206 break;
9380 }
9381 case SUBWIDGEQPITM:
9382 {
9383
1/2
✓ Branch 0 taken 9836 times.
✗ Branch 1 not taken.
9836 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9384 {
9385 9836 ret = 10000*widg->getItemVal();
9386 9836 }
9387 9836 break;
9388 }
9389 case SUBWIDGPAGE:
9390 {
9391 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9392 {
9393 auto [sub,ty,pgid,_ind] = from_subref(ri->subwidgref);
9394 ret = get_subref(sub,ty,pgid,0);
9395 }
9396 break;
9397 }
9398 case SUBWIDGPOS:
9399 {
9400 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9401 ret = 10000*widg->pos;
9402 break;
9403 }
9404 case SUBWIDGX:
9405 {
9406
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 339 times.
339 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9407 339 ret = 10000*widg->x;
9408 339 break;
9409 }
9410 case SUBWIDGY:
9411 {
9412
1/2
✓ Branch 0 taken 339 times.
✗ Branch 1 not taken.
339 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9413 339 ret = 10000*widg->y;
9414 339 break;
9415 }
9416 case SUBWIDGW:
9417 {
9418 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9419 ret = 10000*widg->w;
9420 break;
9421 }
9422 case SUBWIDGH:
9423 {
9424 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9425 ret = 10000*widg->h;
9426 break;
9427 }
9428 case SUBWIDG_DISPX:
9429 {
9430 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9431 ret = 10000*widg->getX();
9432 break;
9433 }
9434 case SUBWIDG_DISPY:
9435 {
9436 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9437 ret = 10000*widg->getY();
9438 break;
9439 }
9440 case SUBWIDG_DISPW:
9441 {
9442 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9443 ret = 10000*widg->getW();
9444 break;
9445 }
9446 case SUBWIDG_DISPH:
9447 {
9448 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9449 ret = 10000*widg->getH();
9450 break;
9451 }
9452 case SUBWIDGREQCOUNTER:
9453 {
9454 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9455 ret = 10000 * widg->req_counter;
9456 break;
9457 }
9458 case SUBWIDGREQCOUNTERCOND:
9459 {
9460 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9461 ret = 10000 * widg->req_counter_cond_type;
9462 break;
9463 }
9464 case SUBWIDGREQCOUNTERVAL:
9465 {
9466 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9467 ret = 10000 * widg->req_counter_val;
9468 break;
9469 }
9470 case SUBWIDGREQLITEMS:
9471 {
9472 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9473 ret = 10000 * widg->req_litems;
9474 break;
9475 }
9476 case SUBWIDGREQLITEMLEVEL:
9477 {
9478 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9479 ret = 10000 * widg->req_litem_level;
9480 break;
9481 }
9482 case SUBWIDGREQSCRIPTDISABLED:
9483 {
9484 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9485 ret = widg->is_disabled ? 10000 : 0;
9486 break;
9487 }
9488 ///---- ACTIVE SUBSCREENS ONLY
9489 case SUBWIDGSELECTORDSTX:
9490 {
9491 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9492 ret = 10000*widg->selector_override.x;
9493 break;
9494 }
9495 case SUBWIDGSELECTORDSTY:
9496 {
9497 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9498 ret = 10000*widg->selector_override.y;
9499 break;
9500 }
9501 case SUBWIDGSELECTORDSTW:
9502 {
9503 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9504 ret = 10000*widg->selector_override.w;
9505 break;
9506 }
9507 case SUBWIDGSELECTORDSTH:
9508 {
9509 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9510 ret = 10000*widg->selector_override.h;
9511 break;
9512 }
9513
9514 case SUBWIDGPRESSSCRIPT:
9515 {
9516 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9517 ret = 10000*widg->generic_script;
9518 break;
9519 }
9520 case SUBWIDGPGMODE:
9521 {
9522 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9523 ret = 10000*widg->pg_mode;
9524 break;
9525 }
9526 case SUBWIDGPGTARG:
9527 {
9528 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9529 ret = 10000*widg->pg_targ;
9530 break;
9531 }
9532
9533 case SUBWIDGTRANSPGTY:
9534 {
9535 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9536 {
9537 auto& trans = widg->pg_trans;
9538 ret = 10000*trans.type;
9539 }
9540 break;
9541 }
9542 case SUBWIDGTRANSPGSFX:
9543 {
9544 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
9545 {
9546 auto& trans = widg->pg_trans;
9547 ret = 10000*trans.tr_sfx;
9548 }
9549 break;
9550 }
9551 ///---- VARYING WIDGET TYPES
9552 case SUBWIDGTY_FONT:
9553 {
9554 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9555 {
9556 auto ty = widg->getType();
9557 switch(ty)
9558 {
9559 case widgTEXT:
9560 ret = 10000*((SW_Text*)widg)->fontid;
9561 break;
9562 case widgTEXTBOX:
9563 ret = 10000*((SW_TextBox*)widg)->fontid;
9564 break;
9565 case widgSELECTEDTEXT:
9566 ret = 10000*((SW_SelectedText*)widg)->fontid;
9567 break;
9568 case widgTIME:
9569 ret = 10000*((SW_Time*)widg)->fontid;
9570 break;
9571 case widgCOUNTER:
9572 ret = 10000*((SW_Counter*)widg)->fontid;
9573 break;
9574 case widgBTNCOUNTER:
9575 ret = 10000*((SW_BtnCounter*)widg)->fontid;
9576 break;
9577 case widgOLDCTR:
9578 ret = 10000*((SW_Counters*)widg)->fontid;
9579 break;
9580 case widgMMAPTITLE:
9581 ret = 10000*((SW_MMapTitle*)widg)->fontid;
9582 break;
9583 default:
9584 bad_subwidg_type(false, ty);
9585 ret = -10000;
9586 break;
9587 }
9588 }
9589 break;
9590 }
9591 case SUBWIDGTY_ALIGN:
9592 {
9593 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9594 {
9595 auto ty = widg->getType();
9596 switch(ty)
9597 {
9598 case widgTEXT:
9599 ret = 10000*((SW_Text*)widg)->align;
9600 break;
9601 case widgTEXTBOX:
9602 ret = 10000*((SW_TextBox*)widg)->align;
9603 break;
9604 case widgSELECTEDTEXT:
9605 ret = 10000*((SW_SelectedText*)widg)->align;
9606 break;
9607 case widgTIME:
9608 ret = 10000*((SW_Time*)widg)->align;
9609 break;
9610 case widgCOUNTER:
9611 ret = 10000*((SW_Counter*)widg)->align;
9612 break;
9613 case widgBTNCOUNTER:
9614 ret = 10000*((SW_BtnCounter*)widg)->align;
9615 break;
9616 case widgMMAPTITLE:
9617 ret = 10000*((SW_MMapTitle*)widg)->align;
9618 break;
9619 default:
9620 bad_subwidg_type(false, ty);
9621 ret = -10000;
9622 break;
9623 }
9624 }
9625 break;
9626 }
9627 case SUBWIDGTY_SHADOWTY:
9628 {
9629 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9630 {
9631 auto ty = widg->getType();
9632 switch(ty)
9633 {
9634 case widgTEXT:
9635 ret = 10000*((SW_Text*)widg)->shadtype;
9636 break;
9637 case widgTEXTBOX:
9638 ret = 10000*((SW_TextBox*)widg)->shadtype;
9639 break;
9640 case widgSELECTEDTEXT:
9641 ret = 10000*((SW_SelectedText*)widg)->shadtype;
9642 break;
9643 case widgTIME:
9644 ret = 10000*((SW_Time*)widg)->shadtype;
9645 break;
9646 case widgCOUNTER:
9647 ret = 10000*((SW_Counter*)widg)->shadtype;
9648 break;
9649 case widgBTNCOUNTER:
9650 ret = 10000*((SW_BtnCounter*)widg)->shadtype;
9651 break;
9652 case widgOLDCTR:
9653 ret = 10000*((SW_Counters*)widg)->shadtype;
9654 break;
9655 case widgMMAPTITLE:
9656 ret = 10000*((SW_MMapTitle*)widg)->shadtype;
9657 break;
9658 default:
9659 bad_subwidg_type(false, ty);
9660 ret = -10000;
9661 break;
9662 }
9663 }
9664 break;
9665 }
9666 case SUBWIDGTY_COLOR_TXT:
9667 {
9668 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9669 {
9670 auto ty = widg->getType();
9671 switch(ty)
9672 {
9673 case widgTEXT:
9674 ret = 10000*((SW_Text*)widg)->c_text.get_int_color();
9675 break;
9676 case widgTEXTBOX:
9677 ret = 10000*((SW_TextBox*)widg)->c_text.get_int_color();
9678 break;
9679 case widgSELECTEDTEXT:
9680 ret = 10000*((SW_SelectedText*)widg)->c_text.get_int_color();
9681 break;
9682 case widgTIME:
9683 ret = 10000*((SW_Time*)widg)->c_text.get_int_color();
9684 break;
9685 case widgCOUNTER:
9686 ret = 10000*((SW_Counter*)widg)->c_text.get_int_color();
9687 break;
9688 case widgBTNCOUNTER:
9689 ret = 10000*((SW_BtnCounter*)widg)->c_text.get_int_color();
9690 break;
9691 case widgOLDCTR:
9692 ret = 10000*((SW_Counters*)widg)->c_text.get_int_color();
9693 break;
9694 case widgMMAPTITLE:
9695 ret = 10000*((SW_MMapTitle*)widg)->c_text.get_int_color();
9696 break;
9697 case widgMCGUFF_FRAME:
9698 ret = 10000*((SW_TriFrame*)widg)->c_number.get_int_color();
9699 break;
9700 default:
9701 bad_subwidg_type(false, ty);
9702 break;
9703 }
9704 }
9705 break;
9706 }
9707 case SUBWIDGTY_COLOR_SHD:
9708 {
9709 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9710 {
9711 auto ty = widg->getType();
9712 switch(ty)
9713 {
9714 case widgTEXT:
9715 ret = 10000*((SW_Text*)widg)->c_shadow.get_int_color();
9716 break;
9717 case widgTEXTBOX:
9718 ret = 10000*((SW_TextBox*)widg)->c_shadow.get_int_color();
9719 break;
9720 case widgSELECTEDTEXT:
9721 ret = 10000*((SW_SelectedText*)widg)->c_shadow.get_int_color();
9722 break;
9723 case widgTIME:
9724 ret = 10000*((SW_Time*)widg)->c_shadow.get_int_color();
9725 break;
9726 case widgCOUNTER:
9727 ret = 10000*((SW_Counter*)widg)->c_shadow.get_int_color();
9728 break;
9729 case widgBTNCOUNTER:
9730 ret = 10000*((SW_BtnCounter*)widg)->c_shadow.get_int_color();
9731 break;
9732 case widgOLDCTR:
9733 ret = 10000*((SW_Counters*)widg)->c_shadow.get_int_color();
9734 break;
9735 case widgMMAPTITLE:
9736 ret = 10000*((SW_MMapTitle*)widg)->c_shadow.get_int_color();
9737 break;
9738 default:
9739 bad_subwidg_type(false, ty);
9740 break;
9741 }
9742 }
9743 break;
9744 }
9745 case SUBWIDGTY_COLOR_BG:
9746 {
9747 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9748 {
9749 auto ty = widg->getType();
9750 switch(ty)
9751 {
9752 case widgTEXT:
9753 ret = 10000*((SW_Text*)widg)->c_bg.get_int_color();
9754 break;
9755 case widgTEXTBOX:
9756 ret = 10000*((SW_TextBox*)widg)->c_bg.get_int_color();
9757 break;
9758 case widgSELECTEDTEXT:
9759 ret = 10000*((SW_SelectedText*)widg)->c_bg.get_int_color();
9760 break;
9761 case widgTIME:
9762 ret = 10000*((SW_Time*)widg)->c_bg.get_int_color();
9763 break;
9764 case widgCOUNTER:
9765 ret = 10000*((SW_Counter*)widg)->c_bg.get_int_color();
9766 break;
9767 case widgBTNCOUNTER:
9768 ret = 10000*((SW_BtnCounter*)widg)->c_bg.get_int_color();
9769 break;
9770 case widgOLDCTR:
9771 ret = 10000*((SW_Counters*)widg)->c_bg.get_int_color();
9772 break;
9773 case widgMMAPTITLE:
9774 ret = 10000*((SW_MMapTitle*)widg)->c_bg.get_int_color();
9775 break;
9776 case widgBGCOLOR:
9777 ret = 10000*((SW_Clear*)widg)->c_bg.get_int_color();
9778 break;
9779 case widgCOUNTERPERCBAR:
9780 ret = 10000*((SW_CounterPercentBar*)widg)->c_bg.get_int_color();
9781 break;
9782 default:
9783 bad_subwidg_type(false, ty);
9784 break;
9785 }
9786 }
9787 break;
9788 }
9789
9790 case SUBWIDGTY_COLOR_TXT2:
9791 {
9792 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9793 {
9794 auto ty = widg->getType();
9795 switch(ty)
9796 {
9797 case widgCOUNTER:
9798 ret = 10000*((SW_Counter*)widg)->c_text2.get_int_color();
9799 break;
9800 case widgBTNCOUNTER:
9801 ret = 10000*((SW_BtnCounter*)widg)->c_text2.get_int_color();
9802 break;
9803 default:
9804 bad_subwidg_type(false, ty);
9805 break;
9806 }
9807 }
9808 break;
9809 }
9810 case SUBWIDGTY_COLOR_SHD2:
9811 {
9812 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9813 {
9814 auto ty = widg->getType();
9815 switch(ty)
9816 {
9817 case widgCOUNTER:
9818 ret = 10000*((SW_Counter*)widg)->c_shadow2.get_int_color();
9819 break;
9820 case widgBTNCOUNTER:
9821 ret = 10000*((SW_BtnCounter*)widg)->c_shadow2.get_int_color();
9822 break;
9823 default:
9824 bad_subwidg_type(false, ty);
9825 break;
9826 }
9827 }
9828 break;
9829 }
9830 case SUBWIDGTY_COLOR_BG2:
9831 {
9832 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9833 {
9834 auto ty = widg->getType();
9835 switch(ty)
9836 {
9837 case widgCOUNTER:
9838 ret = 10000*((SW_Counter*)widg)->c_bg2.get_int_color();
9839 break;
9840 case widgBTNCOUNTER:
9841 ret = 10000*((SW_BtnCounter*)widg)->c_bg2.get_int_color();
9842 break;
9843 default:
9844 bad_subwidg_type(false, ty);
9845 break;
9846 }
9847 }
9848 break;
9849 }
9850 case SUBWIDGTY_COLOR_OLINE:
9851 {
9852 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9853 {
9854 auto ty = widg->getType();
9855 switch(ty)
9856 {
9857 case widgLINE:
9858 ret = 10000*((SW_Line*)widg)->c_line.get_int_color();
9859 break;
9860 case widgRECT:
9861 ret = 10000*((SW_Rect*)widg)->c_outline.get_int_color();
9862 break;
9863 case widgMCGUFF_FRAME:
9864 ret = 10000*((SW_TriFrame*)widg)->c_outline.get_int_color();
9865 break;
9866 default:
9867 bad_subwidg_type(false, ty);
9868 break;
9869 }
9870 }
9871 break;
9872 }
9873 case SUBWIDGTY_COLOR_FILL:
9874 {
9875 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9876 {
9877 auto ty = widg->getType();
9878 switch(ty)
9879 {
9880 case widgRECT:
9881 ret = 10000*((SW_Rect*)widg)->c_fill.get_int_color();
9882 break;
9883 case widgCOUNTERPERCBAR:
9884 ret = 10000*((SW_CounterPercentBar*)widg)->c_fill.get_int_color();
9885 break;
9886 default:
9887 bad_subwidg_type(false, ty);
9888 break;
9889 }
9890 }
9891 break;
9892 }
9893 case SUBWIDGTY_BUTTON:
9894 {
9895 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9896 {
9897 auto ty = widg->getType();
9898 switch(ty)
9899 {
9900 case widgBTNITM:
9901 ret = 10000*((SW_ButtonItem*)widg)->btn;
9902 break;
9903 case widgBTNCOUNTER:
9904 ret = 10000*((SW_BtnCounter*)widg)->btn;
9905 break;
9906 default:
9907 bad_subwidg_type(false, ty);
9908 ret = -10000;
9909 break;
9910 }
9911 }
9912 break;
9913 }
9914 case SUBWIDGTY_MINDIG:
9915 {
9916 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9917 {
9918 auto ty = widg->getType();
9919 switch(ty)
9920 {
9921 case widgCOUNTER:
9922 ret = 10000*((SW_Counter*)widg)->mindigits;
9923 break;
9924 case widgBTNCOUNTER:
9925 ret = 10000*((SW_BtnCounter*)widg)->mindigits;
9926 break;
9927 case widgOLDCTR:
9928 ret = 10000*((SW_Counters*)widg)->digits;
9929 break;
9930 default:
9931 bad_subwidg_type(false, ty);
9932 ret = -10000;
9933 break;
9934 }
9935 }
9936 break;
9937 }
9938 case SUBWIDGTY_MAXDIG:
9939 {
9940 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9941 {
9942 auto ty = widg->getType();
9943 switch(ty)
9944 {
9945 case widgCOUNTER:
9946 ret = 10000*((SW_Counter*)widg)->maxdigits;
9947 break;
9948 case widgBTNCOUNTER:
9949 ret = 10000*((SW_BtnCounter*)widg)->maxdigits;
9950 break;
9951 default:
9952 bad_subwidg_type(false, ty);
9953 ret = -10000;
9954 break;
9955 }
9956 }
9957 break;
9958 }
9959 case SUBWIDGTY_INFITM:
9960 {
9961 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9962 {
9963 auto ty = widg->getType();
9964 switch(ty)
9965 {
9966 case widgCOUNTER:
9967 ret = 10000*((SW_Counter*)widg)->infitm;
9968 break;
9969 case widgOLDCTR:
9970 ret = 10000*((SW_Counters*)widg)->infitm;
9971 break;
9972 case widgLGAUGE:
9973 case widgMGAUGE:
9974 case widgMISCGAUGE:
9975 ret = 10000*((SW_GaugePiece*)widg)->inf_item;
9976 break;
9977 default:
9978 bad_subwidg_type(false, ty);
9979 ret = -10000;
9980 break;
9981 }
9982 }
9983 break;
9984 }
9985 case SUBWIDGTY_INFCHAR:
9986 {
9987 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
9988 {
9989 auto ty = widg->getType();
9990 switch(ty)
9991 {
9992 case widgCOUNTER:
9993 ret = 10000*byte(((SW_Counter*)widg)->infchar);
9994 break;
9995 case widgOLDCTR:
9996 ret = 10000*byte(((SW_Counters*)widg)->infchar);
9997 break;
9998 case widgBTNCOUNTER:
9999 ret = 10000*byte(((SW_BtnCounter*)widg)->infchar);
10000 break;
10001 default:
10002 bad_subwidg_type(false, ty);
10003 break;
10004 }
10005 }
10006 break;
10007 }
10008 case SUBWIDGTY_COSTIND:
10009 {
10010 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10011 {
10012 auto ty = widg->getType();
10013 switch(ty)
10014 {
10015 case widgBTNCOUNTER:
10016 ret = 10000*((SW_BtnCounter*)widg)->costind;
10017 break;
10018 default:
10019 bad_subwidg_type(false, ty);
10020 ret = -1;
10021 break;
10022 }
10023 }
10024 break;
10025 }
10026 case SUBWIDGTY_COLOR_PLAYER:
10027 {
10028 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10029 {
10030 auto ty = widg->getType();
10031 switch(ty)
10032 {
10033 case widgMMAP:
10034 ret = 10000*((SW_MMap*)widg)->c_plr.get_int_color();
10035 break;
10036 case widgLMAP:
10037 ret = 10000*((SW_LMap*)widg)->c_plr.get_int_color();
10038 break;
10039 default:
10040 bad_subwidg_type(false, ty);
10041 break;
10042 }
10043 }
10044 break;
10045 }
10046 case SUBWIDGTY_COLOR_CMPBLNK:
10047 {
10048 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10049 {
10050 auto ty = widg->getType();
10051 switch(ty)
10052 {
10053 case widgMMAP:
10054 ret = 10000*((SW_MMap*)widg)->c_cmp_blink.get_int_color();
10055 break;
10056 default:
10057 bad_subwidg_type(false, ty);
10058 break;
10059 }
10060 }
10061 break;
10062 }
10063 case SUBWIDGTY_COLOR_CMPOFF:
10064 {
10065 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10066 {
10067 auto ty = widg->getType();
10068 switch(ty)
10069 {
10070 case widgMMAP:
10071 ret = 10000*((SW_MMap*)widg)->c_cmp_off.get_int_color();
10072 break;
10073 default:
10074 bad_subwidg_type(false, ty);
10075 break;
10076 }
10077 }
10078 break;
10079 }
10080 case SUBWIDGTY_COLOR_ROOM:
10081 {
10082 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10083 {
10084 auto ty = widg->getType();
10085 switch(ty)
10086 {
10087 case widgLMAP:
10088 ret = 10000*((SW_LMap*)widg)->c_room.get_int_color();
10089 break;
10090 default:
10091 bad_subwidg_type(false, ty);
10092 break;
10093 }
10094 }
10095 break;
10096 }
10097 case SUBWIDGTY_ITEMCLASS:
10098 {
10099 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10100 {
10101 auto ty = widg->getType();
10102 switch(ty)
10103 {
10104 case widgITEMSLOT:
10105 ret = 10000*((SW_ItemSlot*)widg)->iclass;
10106 break;
10107 default:
10108 bad_subwidg_type(false, ty);
10109 break;
10110 }
10111 }
10112 break;
10113 }
10114 case SUBWIDGTY_ITEMID:
10115 {
10116
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1455 times.
1455 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10117 {
10118 1455 auto ty = widg->getType();
10119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1455 times.
1455 switch(ty)
10120 {
10121 case widgITEMSLOT:
10122 1455 ret = 10000*((SW_ItemSlot*)widg)->iid;
10123 1455 break;
10124 default:
10125 bad_subwidg_type(false, ty);
10126 break;
10127 }
10128 1455 }
10129 1455 break;
10130 }
10131 case SUBWIDGTY_FRAMETILE:
10132 {
10133 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10134 {
10135 auto ty = widg->getType();
10136 switch(ty)
10137 {
10138 case widgMCGUFF_FRAME:
10139 ret = 10000*((SW_TriFrame*)widg)->frame_tile;
10140 break;
10141 default:
10142 bad_subwidg_type(false, ty);
10143 break;
10144 }
10145 }
10146 break;
10147 }
10148 case SUBWIDGTY_FRAMECSET:
10149 {
10150 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10151 {
10152 auto ty = widg->getType();
10153 switch(ty)
10154 {
10155 case widgMCGUFF_FRAME:
10156 ret = 10000*((SW_TriFrame*)widg)->frame_cset;
10157 break;
10158 default:
10159 bad_subwidg_type(false, ty);
10160 break;
10161 }
10162 }
10163 break;
10164 }
10165 case SUBWIDGTY_PIECETILE:
10166 {
10167 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10168 {
10169 auto ty = widg->getType();
10170 switch(ty)
10171 {
10172 case widgMCGUFF_FRAME:
10173 ret = 10000*((SW_TriFrame*)widg)->piece_tile;
10174 break;
10175 default:
10176 bad_subwidg_type(false, ty);
10177 break;
10178 }
10179 }
10180 break;
10181 }
10182 case SUBWIDGTY_PIECECSET:
10183 {
10184 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10185 {
10186 auto ty = widg->getType();
10187 switch(ty)
10188 {
10189 case widgMCGUFF_FRAME:
10190 ret = 10000*((SW_TriFrame*)widg)->piece_cset;
10191 break;
10192 default:
10193 bad_subwidg_type(false, ty);
10194 break;
10195 }
10196 }
10197 break;
10198 }
10199 case SUBWIDGTY_FLIP:
10200 {
10201 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10202 {
10203 auto ty = widg->getType();
10204 switch(ty)
10205 {
10206 case widgMCGUFF:
10207 ret = 10000*((SW_McGuffin*)widg)->flip;
10208 break;
10209 case widgTILEBLOCK:
10210 ret = 10000*((SW_TileBlock*)widg)->flip;
10211 break;
10212 case widgMINITILE:
10213 ret = 10000*((SW_MiniTile*)widg)->flip;
10214 break;
10215 default:
10216 bad_subwidg_type(false, ty);
10217 break;
10218 }
10219 }
10220 break;
10221 }
10222 case SUBWIDGTY_NUMBER:
10223 {
10224 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10225 {
10226 auto ty = widg->getType();
10227 switch(ty)
10228 {
10229 case widgMCGUFF:
10230 ret = 10000*((SW_McGuffin*)widg)->number;
10231 break;
10232 default:
10233 bad_subwidg_type(false, ty);
10234 break;
10235 }
10236 }
10237 break;
10238 }
10239 case SUBWIDGTY_FRAMES:
10240 {
10241 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10242 {
10243 auto ty = widg->getType();
10244 switch(ty)
10245 {
10246 case widgLGAUGE:
10247 case widgMGAUGE:
10248 case widgMISCGAUGE:
10249 ret = 10000*((SW_GaugePiece*)widg)->frames;
10250 break;
10251 default:
10252 bad_subwidg_type(false, ty);
10253 ret = -10000;
10254 break;
10255 }
10256 }
10257 break;
10258 }
10259 case SUBWIDGTY_SPEED:
10260 {
10261 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10262 {
10263 auto ty = widg->getType();
10264 switch(ty)
10265 {
10266 case widgLGAUGE:
10267 case widgMGAUGE:
10268 case widgMISCGAUGE:
10269 ret = 10000*((SW_GaugePiece*)widg)->speed;
10270 break;
10271 default:
10272 bad_subwidg_type(false, ty);
10273 ret = -10000;
10274 break;
10275 }
10276 }
10277 break;
10278 }
10279 case SUBWIDGTY_DELAY:
10280 {
10281 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10282 {
10283 auto ty = widg->getType();
10284 switch(ty)
10285 {
10286 case widgLGAUGE:
10287 case widgMGAUGE:
10288 case widgMISCGAUGE:
10289 ret = 10000*((SW_GaugePiece*)widg)->delay;
10290 break;
10291 default:
10292 bad_subwidg_type(false, ty);
10293 ret = -10000;
10294 break;
10295 }
10296 }
10297 break;
10298 }
10299 case SUBWIDGTY_CONTAINER:
10300 {
10301 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10302 {
10303 auto ty = widg->getType();
10304 switch(ty)
10305 {
10306 case widgLGAUGE:
10307 case widgMGAUGE:
10308 case widgMISCGAUGE:
10309 ret = 10000*((SW_GaugePiece*)widg)->container;
10310 break;
10311 default:
10312 bad_subwidg_type(false, ty);
10313 ret = -10000;
10314 break;
10315 }
10316 }
10317 break;
10318 }
10319 case SUBWIDGTY_GAUGE_WID:
10320 {
10321 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10322 {
10323 auto ty = widg->getType();
10324 switch(ty)
10325 {
10326 case widgLGAUGE:
10327 case widgMGAUGE:
10328 case widgMISCGAUGE:
10329 ret = 10000*(((SW_GaugePiece*)widg)->gauge_wid+1);
10330 break;
10331 default:
10332 bad_subwidg_type(false, ty);
10333 ret = -10000;
10334 break;
10335 }
10336 }
10337 break;
10338 }
10339 case SUBWIDGTY_GAUGE_HEI:
10340 {
10341 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10342 {
10343 auto ty = widg->getType();
10344 switch(ty)
10345 {
10346 case widgLGAUGE:
10347 case widgMGAUGE:
10348 case widgMISCGAUGE:
10349 ret = 10000*(((SW_GaugePiece*)widg)->gauge_hei+1);
10350 break;
10351 default:
10352 bad_subwidg_type(false, ty);
10353 ret = -10000;
10354 break;
10355 }
10356 }
10357 break;
10358 }
10359 case SUBWIDGTY_UNITS:
10360 {
10361 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10362 {
10363 auto ty = widg->getType();
10364 switch(ty)
10365 {
10366 case widgLGAUGE:
10367 case widgMGAUGE:
10368 case widgMISCGAUGE:
10369 ret = 10000*(((SW_GaugePiece*)widg)->unit_per_frame+1);
10370 break;
10371 default:
10372 bad_subwidg_type(false, ty);
10373 ret = -10000;
10374 break;
10375 }
10376 }
10377 break;
10378 }
10379 case SUBWIDGTY_HSPACE:
10380 {
10381 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10382 {
10383 auto ty = widg->getType();
10384 switch(ty)
10385 {
10386 case widgLGAUGE:
10387 case widgMGAUGE:
10388 case widgMISCGAUGE:
10389 ret = 10000*((SW_GaugePiece*)widg)->hspace;
10390 break;
10391 default:
10392 bad_subwidg_type(false, ty);
10393 ret = -10000;
10394 break;
10395 }
10396 }
10397 break;
10398 }
10399 case SUBWIDGTY_VSPACE:
10400 {
10401 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10402 {
10403 auto ty = widg->getType();
10404 switch(ty)
10405 {
10406 case widgLGAUGE:
10407 case widgMGAUGE:
10408 case widgMISCGAUGE:
10409 ret = 10000*((SW_GaugePiece*)widg)->vspace;
10410 break;
10411 default:
10412 bad_subwidg_type(false, ty);
10413 ret = -10000;
10414 break;
10415 }
10416 }
10417 break;
10418 }
10419 case SUBWIDGTY_GRIDX:
10420 {
10421 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10422 {
10423 auto ty = widg->getType();
10424 switch(ty)
10425 {
10426 case widgLGAUGE:
10427 case widgMGAUGE:
10428 case widgMISCGAUGE:
10429 ret = 10000*((SW_GaugePiece*)widg)->grid_xoff;
10430 break;
10431 default:
10432 bad_subwidg_type(false, ty);
10433 ret = -10000;
10434 break;
10435 }
10436 }
10437 break;
10438 }
10439 case SUBWIDGTY_GRIDY:
10440 {
10441 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10442 {
10443 auto ty = widg->getType();
10444 switch(ty)
10445 {
10446 case widgLGAUGE:
10447 case widgMGAUGE:
10448 case widgMISCGAUGE:
10449 ret = 10000*((SW_GaugePiece*)widg)->grid_yoff;
10450 break;
10451 default:
10452 bad_subwidg_type(false, ty);
10453 ret = -10000;
10454 break;
10455 }
10456 }
10457 break;
10458 }
10459 case SUBWIDGTY_ANIMVAL:
10460 {
10461 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10462 {
10463 auto ty = widg->getType();
10464 switch(ty)
10465 {
10466 case widgLGAUGE:
10467 case widgMGAUGE:
10468 case widgMISCGAUGE:
10469 ret = 10000*((SW_GaugePiece*)widg)->anim_val;
10470 break;
10471 default:
10472 bad_subwidg_type(false, ty);
10473 ret = -10000;
10474 break;
10475 }
10476 }
10477 break;
10478 }
10479 case SUBWIDGTY_SHOWDRAIN:
10480 {
10481 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10482 {
10483 auto ty = widg->getType();
10484 switch(ty)
10485 {
10486 case widgMGAUGE:
10487 ret = 10000*((SW_MagicGaugePiece*)widg)->showdrain;
10488 break;
10489 default:
10490 bad_subwidg_type(false, ty);
10491 ret = -10000;
10492 break;
10493 }
10494 }
10495 break;
10496 }
10497 case SUBWIDGTY_PERCONTAINER:
10498 {
10499 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10500 {
10501 auto ty = widg->getType();
10502 switch(ty)
10503 {
10504 case widgMISCGAUGE:
10505 ret = 10000*((SW_MiscGaugePiece*)widg)->per_container;
10506 break;
10507 default:
10508 bad_subwidg_type(false, ty);
10509 ret = -10000;
10510 break;
10511 }
10512 }
10513 break;
10514 }
10515 case SUBWIDGTY_TABSIZE:
10516 {
10517 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10518 {
10519 auto ty = widg->getType();
10520 switch(ty)
10521 {
10522 case widgTEXTBOX:
10523 ret = 10000*((SW_TextBox*)widg)->tabsize;
10524 break;
10525 case widgSELECTEDTEXT:
10526 ret = 10000*((SW_SelectedText*)widg)->tabsize;
10527 break;
10528 default:
10529 bad_subwidg_type(false, ty);
10530 ret = -10000;
10531 break;
10532 }
10533 }
10534 break;
10535 }
10536 case SUBWIDGTY_LITEMS:
10537 {
10538 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
10539 {
10540 auto ty = widg->getType();
10541 switch(ty)
10542 {
10543 case widgMMAP:
10544 ret = 10000*((SW_MMap*)widg)->compass_litems;
10545 break;
10546 default:
10547 bad_subwidg_type(false, ty);
10548 ret = -10000;
10549 break;
10550 }
10551 }
10552 break;
10553 }
10554
10555 default:
10556 {
10557
2/2
✓ Branch 0 taken 394576415 times.
✓ Branch 1 taken 237946193 times.
632522608 if (zasm_array_supports(arg))
10558 {
10559 394576415 int ref_arg = get_register_ref_dependency(arg).value_or(0);
10560
2/2
✓ Branch 0 taken 218361278 times.
✓ Branch 1 taken 176215137 times.
394576415 int ref = ref_arg ? get_ref(ref_arg) : 0;
10561 394576415 ret = zasm_array_get(arg, ref, ri->d[rINDEX] / 10000);
10562 394576415 }
10563
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 237946193 times.
237946193 else if (auto r = scripting_engine_get_register(arg))
10564 237946193 ret = *r;
10565 632522608 break;
10566 }
10567 }
10568
10569 2846222550 current_zasm_register = 0;
10570
10571 2846222550 return ret;
10572 3968762533 }
10573
10574 //Setter Instructions
10575
10576
10577 2111466290 void set_register(int32_t arg, int32_t value)
10578 {
10579
3/4
✓ Branch 0 taken 2111466290 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1622646883 times.
✓ Branch 3 taken 488819407 times.
2111466290 if (arg >= D(0) && arg <= D(7))
10580 {
10581 488819407 ri->d[arg - D(0)] = value;
10582 488819407 return;
10583 }
10584
4/4
✓ Branch 0 taken 1589113433 times.
✓ Branch 1 taken 33533450 times.
✓ Branch 2 taken 1589112529 times.
✓ Branch 3 taken 904 times.
1622646883 else if (arg >= GD(0) && arg <= GD(MAX_SCRIPT_REGISTERS))
10585 {
10586 904 game->global_d[arg-GD(0)] = value;
10587 904 return;
10588 }
10589
10590 //Macros
10591
10592 #define SET_SPRITEDATA_VAR_INT(member, str) \
10593 { \
10594 if(unsigned(ri->spritedataref) > (MAXWPNS-1) ) \
10595 { \
10596 Z_scripterrlog("Invalid Sprite ID passed to spritedata->%s: %d\n", str, (ri->spritedataref*10000)); \
10597 } \
10598 else \
10599 { \
10600 wpnsbuf[ri->spritedataref].member = vbound((value / 10000),0,214747); \
10601 } \
10602 } \
10603
10604 #define SET_SPRITEDATA_VAR_BYTE(member, str) \
10605 { \
10606 if(unsigned(ri->spritedataref) > (MAXWPNS-1) ) \
10607 { \
10608 Z_scripterrlog("Invalid Sprite ID passed to spritedata->%s: %d\n", str, (ri->spritedataref*10000)); \
10609 } \
10610 else \
10611 { \
10612 wpnsbuf[ri->spritedataref].member = vbound((value / 10000),0,255); \
10613 } \
10614 } \
10615
10616 1622645979 current_zasm_register = arg;
10617
10618 // Do not ever use `return` in these cases!
10619
221/969
✓ Branch 0 taken 4499468 times.
✓ Branch 1 taken 14116 times.
✓ Branch 2 taken 2047856 times.
✓ Branch 3 taken 3675 times.
✓ Branch 4 taken 2299966 times.
✓ Branch 5 taken 2299127 times.
✓ Branch 6 taken 13913 times.
✓ Branch 7 taken 14191 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 14321 times.
✓ Branch 10 taken 16029 times.
✓ Branch 11 taken 4145 times.
✓ Branch 12 taken 4147 times.
✓ Branch 13 taken 13890 times.
✓ Branch 14 taken 13913 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 809 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 76581 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 2220 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 60 times.
✓ Branch 25 taken 48 times.
✗ Branch 26 not taken.
✓ Branch 27 taken 837 times.
✓ Branch 28 taken 2288 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 718 times.
✓ Branch 31 taken 5878 times.
✓ Branch 32 taken 1 times.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✓ Branch 35 taken 26326 times.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✓ Branch 46 taken 3 times.
✓ Branch 47 taken 277656 times.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✓ Branch 51 taken 290 times.
✓ Branch 52 taken 4859 times.
✓ Branch 53 taken 3652 times.
✓ Branch 54 taken 2578 times.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✓ Branch 65 taken 4 times.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✓ Branch 82 taken 646198 times.
✓ Branch 83 taken 298036 times.
✓ Branch 84 taken 295303 times.
✓ Branch 85 taken 281941 times.
✓ Branch 86 taken 281894 times.
✓ Branch 87 taken 186826 times.
✓ Branch 88 taken 120700 times.
✓ Branch 89 taken 118163 times.
✓ Branch 90 taken 118214 times.
✓ Branch 91 taken 262073 times.
✓ Branch 92 taken 262073 times.
✓ Branch 93 taken 262073 times.
✓ Branch 94 taken 262073 times.
✗ Branch 95 not taken.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✓ Branch 99 taken 1121819 times.
✓ Branch 100 taken 646198 times.
✓ Branch 101 taken 261563 times.
✓ Branch 102 taken 261555 times.
✓ Branch 103 taken 261628 times.
✓ Branch 104 taken 261662 times.
✓ Branch 105 taken 177542 times.
✓ Branch 106 taken 111830 times.
✓ Branch 107 taken 115219 times.
✓ Branch 108 taken 115270 times.
✓ Branch 109 taken 262073 times.
✓ Branch 110 taken 262073 times.
✓ Branch 111 taken 262073 times.
✓ Branch 112 taken 262073 times.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✗ Branch 116 not taken.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✗ Branch 119 not taken.
✗ Branch 120 not taken.
✗ Branch 121 not taken.
✗ Branch 122 not taken.
✗ Branch 123 not taken.
✗ Branch 124 not taken.
✗ Branch 125 not taken.
✗ Branch 126 not taken.
✗ Branch 127 not taken.
✗ Branch 128 not taken.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✗ Branch 132 not taken.
✗ Branch 133 not taken.
✗ Branch 134 not taken.
✗ Branch 135 not taken.
✓ Branch 136 taken 214057 times.
✓ Branch 137 taken 1 times.
✓ Branch 138 taken 214043 times.
✓ Branch 139 taken 971 times.
✓ Branch 140 taken 408 times.
✗ Branch 141 not taken.
✓ Branch 142 taken 71609 times.
✗ Branch 143 not taken.
✗ Branch 144 not taken.
✓ Branch 145 taken 1679 times.
✗ Branch 146 not taken.
✓ Branch 147 taken 6 times.
✓ Branch 148 taken 6 times.
✓ Branch 149 taken 1181 times.
✗ Branch 150 not taken.
✓ Branch 151 taken 1131 times.
✓ Branch 152 taken 476 times.
✓ Branch 153 taken 76041 times.
✓ Branch 154 taken 153795 times.
✗ Branch 155 not taken.
✓ Branch 156 taken 2464 times.
✓ Branch 157 taken 3263 times.
✗ Branch 158 not taken.
✓ Branch 159 taken 26540 times.
✓ Branch 160 taken 6 times.
✓ Branch 161 taken 6 times.
✓ Branch 162 taken 527 times.
✓ Branch 163 taken 6 times.
✓ Branch 164 taken 839 times.
✓ Branch 165 taken 2345 times.
✓ Branch 166 taken 6 times.
✓ Branch 167 taken 71310 times.
✓ Branch 168 taken 1768 times.
✓ Branch 169 taken 70954 times.
✗ Branch 170 not taken.
✗ Branch 171 not taken.
✗ Branch 172 not taken.
✓ Branch 173 taken 6 times.
✓ Branch 174 taken 72525 times.
✓ Branch 175 taken 72542 times.
✓ Branch 176 taken 6 times.
✓ Branch 177 taken 833 times.
✓ Branch 178 taken 833 times.
✓ Branch 179 taken 18928 times.
✗ Branch 180 not taken.
✓ Branch 181 taken 42 times.
✓ Branch 182 taken 12 times.
✓ Branch 183 taken 62002 times.
✓ Branch 184 taken 1130 times.
✗ Branch 185 not taken.
✗ Branch 186 not taken.
✗ Branch 187 not taken.
✗ Branch 188 not taken.
✓ Branch 189 taken 527 times.
✗ Branch 190 not taken.
✗ Branch 191 not taken.
✗ Branch 192 not taken.
✗ Branch 193 not taken.
✗ Branch 194 not taken.
✗ Branch 195 not taken.
✗ Branch 196 not taken.
✗ Branch 197 not taken.
✗ Branch 198 not taken.
✗ Branch 199 not taken.
✗ Branch 200 not taken.
✗ Branch 201 not taken.
✓ Branch 202 taken 390183 times.
✓ Branch 203 taken 1 times.
✓ Branch 204 taken 390780 times.
✓ Branch 205 taken 57530 times.
✓ Branch 206 taken 55587 times.
✗ Branch 207 not taken.
✓ Branch 208 taken 227256 times.
✓ Branch 209 taken 117 times.
✗ Branch 210 not taken.
✓ Branch 211 taken 372485 times.
✓ Branch 212 taken 220890 times.
✗ Branch 213 not taken.
✗ Branch 214 not taken.
✗ Branch 215 not taken.
✓ Branch 216 taken 208988 times.
✗ Branch 217 not taken.
✓ Branch 218 taken 5420 times.
✓ Branch 219 taken 12175 times.
✓ Branch 220 taken 210232 times.
✓ Branch 221 taken 114186 times.
✗ Branch 222 not taken.
✓ Branch 223 taken 74446 times.
✓ Branch 224 taken 178 times.
✗ Branch 225 not taken.
✓ Branch 226 taken 35337 times.
✗ Branch 227 not taken.
✓ Branch 228 taken 41 times.
✓ Branch 229 taken 1039 times.
✓ Branch 230 taken 41 times.
✓ Branch 231 taken 549 times.
✓ Branch 232 taken 78832 times.
✓ Branch 233 taken 156969 times.
✓ Branch 234 taken 4552 times.
✗ Branch 235 not taken.
✓ Branch 236 taken 194229 times.
✓ Branch 237 taken 193736 times.
✓ Branch 238 taken 84994 times.
✗ Branch 239 not taken.
✗ Branch 240 not taken.
✗ Branch 241 not taken.
✓ Branch 242 taken 325611 times.
✓ Branch 243 taken 325024 times.
✓ Branch 244 taken 44 times.
✓ Branch 245 taken 202345 times.
✓ Branch 246 taken 202345 times.
✓ Branch 247 taken 31616 times.
✗ Branch 248 not taken.
✗ Branch 249 not taken.
✗ Branch 250 not taken.
✓ Branch 251 taken 1621 times.
✗ Branch 252 not taken.
✗ Branch 253 not taken.
✗ Branch 254 not taken.
✗ Branch 255 not taken.
✗ Branch 256 not taken.
✓ Branch 257 taken 4 times.
✗ Branch 258 not taken.
✗ Branch 259 not taken.
✗ Branch 260 not taken.
✗ Branch 261 not taken.
✗ Branch 262 not taken.
✗ Branch 263 not taken.
✗ Branch 264 not taken.
✗ Branch 265 not taken.
✗ Branch 266 not taken.
✗ Branch 267 not taken.
✗ Branch 268 not taken.
✗ Branch 269 not taken.
✗ Branch 270 not taken.
✓ Branch 271 taken 6 times.
✓ Branch 272 taken 360 times.
✓ Branch 273 taken 360 times.
✗ Branch 274 not taken.
✗ Branch 275 not taken.
✗ Branch 276 not taken.
✗ Branch 277 not taken.
✗ Branch 278 not taken.
✗ Branch 279 not taken.
✗ Branch 280 not taken.
✗ Branch 281 not taken.
✗ Branch 282 not taken.
✗ Branch 283 not taken.
✗ Branch 284 not taken.
✗ Branch 285 not taken.
✗ Branch 286 not taken.
✗ Branch 287 not taken.
✗ Branch 288 not taken.
✗ Branch 289 not taken.
✗ Branch 290 not taken.
✗ Branch 291 not taken.
✗ Branch 292 not taken.
✗ Branch 293 not taken.
✗ Branch 294 not taken.
✗ Branch 295 not taken.
✗ Branch 296 not taken.
✗ Branch 297 not taken.
✗ Branch 298 not taken.
✗ Branch 299 not taken.
✗ Branch 300 not taken.
✗ Branch 301 not taken.
✗ Branch 302 not taken.
✗ Branch 303 not taken.
✗ Branch 304 not taken.
✗ Branch 305 not taken.
✗ Branch 306 not taken.
✓ Branch 307 taken 30 times.
✓ Branch 308 taken 30 times.
✗ Branch 309 not taken.
✗ Branch 310 not taken.
✗ Branch 311 not taken.
✗ Branch 312 not taken.
✗ Branch 313 not taken.
✗ Branch 314 not taken.
✓ Branch 315 taken 10 times.
✗ Branch 316 not taken.
✗ Branch 317 not taken.
✗ Branch 318 not taken.
✗ Branch 319 not taken.
✗ Branch 320 not taken.
✗ Branch 321 not taken.
✗ Branch 322 not taken.
✗ Branch 323 not taken.
✗ Branch 324 not taken.
✓ Branch 325 taken 27297 times.
✓ Branch 326 taken 536 times.
✗ Branch 327 not taken.
✓ Branch 328 taken 900 times.
✓ Branch 329 taken 7396 times.
✓ Branch 330 taken 6502 times.
✗ Branch 331 not taken.
✓ Branch 332 taken 11 times.
✗ Branch 333 not taken.
✗ Branch 334 not taken.
✗ Branch 335 not taken.
✗ Branch 336 not taken.
✗ Branch 337 not taken.
✓ Branch 338 taken 5310 times.
✓ Branch 339 taken 114 times.
✗ Branch 340 not taken.
✗ Branch 341 not taken.
✗ Branch 342 not taken.
✗ Branch 343 not taken.
✗ Branch 344 not taken.
✗ Branch 345 not taken.
✗ Branch 346 not taken.
✗ Branch 347 not taken.
✗ Branch 348 not taken.
✗ Branch 349 not taken.
✗ Branch 350 not taken.
✗ Branch 351 not taken.
✗ Branch 352 not taken.
✗ Branch 353 not taken.
✗ Branch 354 not taken.
✗ Branch 355 not taken.
✗ Branch 356 not taken.
✗ Branch 357 not taken.
✗ Branch 358 not taken.
✗ Branch 359 not taken.
✗ Branch 360 not taken.
✗ Branch 361 not taken.
✗ Branch 362 not taken.
✗ Branch 363 not taken.
✗ Branch 364 not taken.
✗ Branch 365 not taken.
✗ Branch 366 not taken.
✗ Branch 367 not taken.
✗ Branch 368 not taken.
✗ Branch 369 not taken.
✗ Branch 370 not taken.
✗ Branch 371 not taken.
✗ Branch 372 not taken.
✗ Branch 373 not taken.
✗ Branch 374 not taken.
✗ Branch 375 not taken.
✗ Branch 376 not taken.
✗ Branch 377 not taken.
✗ Branch 378 not taken.
✗ Branch 379 not taken.
✗ Branch 380 not taken.
✗ Branch 381 not taken.
✗ Branch 382 not taken.
✗ Branch 383 not taken.
✗ Branch 384 not taken.
✓ Branch 385 taken 20 times.
✗ Branch 386 not taken.
✗ Branch 387 not taken.
✗ Branch 388 not taken.
✗ Branch 389 not taken.
✗ Branch 390 not taken.
✗ Branch 391 not taken.
✓ Branch 392 taken 5120 times.
✗ Branch 393 not taken.
✗ Branch 394 not taken.
✗ Branch 395 not taken.
✗ Branch 396 not taken.
✗ Branch 397 not taken.
✗ Branch 398 not taken.
✗ Branch 399 not taken.
✗ Branch 400 not taken.
✗ Branch 401 not taken.
✗ Branch 402 not taken.
✓ Branch 403 taken 3225 times.
✗ Branch 404 not taken.
✗ Branch 405 not taken.
✗ Branch 406 not taken.
✗ Branch 407 not taken.
✗ Branch 408 not taken.
✗ Branch 409 not taken.
✗ Branch 410 not taken.
✗ Branch 411 not taken.
✗ Branch 412 not taken.
✗ Branch 413 not taken.
✗ Branch 414 not taken.
✗ Branch 415 not taken.
✗ Branch 416 not taken.
✗ Branch 417 not taken.
✗ Branch 418 not taken.
✗ Branch 419 not taken.
✗ Branch 420 not taken.
✗ Branch 421 not taken.
✗ Branch 422 not taken.
✗ Branch 423 not taken.
✗ Branch 424 not taken.
✗ Branch 425 not taken.
✗ Branch 426 not taken.
✗ Branch 427 not taken.
✗ Branch 428 not taken.
✗ Branch 429 not taken.
✗ Branch 430 not taken.
✗ Branch 431 not taken.
✗ Branch 432 not taken.
✗ Branch 433 not taken.
✗ Branch 434 not taken.
✗ Branch 435 not taken.
✗ Branch 436 not taken.
✗ Branch 437 not taken.
✗ Branch 438 not taken.
✗ Branch 439 not taken.
✗ Branch 440 not taken.
✗ Branch 441 not taken.
✗ Branch 442 not taken.
✗ Branch 443 not taken.
✗ Branch 444 not taken.
✗ Branch 445 not taken.
✗ Branch 446 not taken.
✗ Branch 447 not taken.
✗ Branch 448 not taken.
✗ Branch 449 not taken.
✗ Branch 450 not taken.
✗ Branch 451 not taken.
✗ Branch 452 not taken.
✗ Branch 453 not taken.
✗ Branch 454 not taken.
✗ Branch 455 not taken.
✗ Branch 456 not taken.
✗ Branch 457 not taken.
✗ Branch 458 not taken.
✗ Branch 459 not taken.
✗ Branch 460 not taken.
✗ Branch 461 not taken.
✗ Branch 462 not taken.
✓ Branch 463 taken 4 times.
✓ Branch 464 taken 2239361 times.
✓ Branch 465 taken 6367264 times.
✓ Branch 466 taken 12117383 times.
✓ Branch 467 taken 46788128 times.
✓ Branch 468 taken 162664402 times.
✓ Branch 469 taken 43220079 times.
✓ Branch 470 taken 88305847 times.
✗ Branch 471 not taken.
✓ Branch 472 taken 838813 times.
✗ Branch 473 not taken.
✓ Branch 474 taken 64 times.
✓ Branch 475 taken 410111 times.
✓ Branch 476 taken 1 times.
✓ Branch 477 taken 77218 times.
✗ Branch 478 not taken.
✓ Branch 479 taken 124 times.
✓ Branch 480 taken 10 times.
✗ Branch 481 not taken.
✗ Branch 482 not taken.
✓ Branch 483 taken 8474693 times.
✓ Branch 484 taken 284 times.
✗ Branch 485 not taken.
✗ Branch 486 not taken.
✓ Branch 487 taken 109743 times.
✓ Branch 488 taken 20806 times.
✓ Branch 489 taken 103742 times.
✓ Branch 490 taken 449481 times.
✗ Branch 491 not taken.
✓ Branch 492 taken 3373 times.
✓ Branch 493 taken 1113 times.
✓ Branch 494 taken 7263 times.
✓ Branch 495 taken 115 times.
✓ Branch 496 taken 38 times.
✗ Branch 497 not taken.
✗ Branch 498 not taken.
✗ Branch 499 not taken.
✗ Branch 500 not taken.
✗ Branch 501 not taken.
✗ Branch 502 not taken.
✗ Branch 503 not taken.
✗ Branch 504 not taken.
✗ Branch 505 not taken.
✗ Branch 506 not taken.
✗ Branch 507 not taken.
✗ Branch 508 not taken.
✗ Branch 509 not taken.
✗ Branch 510 not taken.
✗ Branch 511 not taken.
✗ Branch 512 not taken.
✗ Branch 513 not taken.
✗ Branch 514 not taken.
✗ Branch 515 not taken.
✗ Branch 516 not taken.
✗ Branch 517 not taken.
✗ Branch 518 not taken.
✗ Branch 519 not taken.
✓ Branch 520 taken 3 times.
✗ Branch 521 not taken.
✗ Branch 522 not taken.
✗ Branch 523 not taken.
✗ Branch 524 not taken.
✗ Branch 525 not taken.
✗ Branch 526 not taken.
✗ Branch 527 not taken.
✗ Branch 528 not taken.
✗ Branch 529 not taken.
✗ Branch 530 not taken.
✓ Branch 531 taken 11 times.
✓ Branch 532 taken 11 times.
✓ Branch 533 taken 11 times.
✓ Branch 534 taken 11 times.
✗ Branch 535 not taken.
✗ Branch 536 not taken.
✗ Branch 537 not taken.
✗ Branch 538 not taken.
✗ Branch 539 not taken.
✗ Branch 540 not taken.
✗ Branch 541 not taken.
✗ Branch 542 not taken.
✗ Branch 543 not taken.
✗ Branch 544 not taken.
✓ Branch 545 taken 132 times.
✓ Branch 546 taken 4247 times.
✗ Branch 547 not taken.
✗ Branch 548 not taken.
✗ Branch 549 not taken.
✗ Branch 550 not taken.
✗ Branch 551 not taken.
✗ Branch 552 not taken.
✗ Branch 553 not taken.
✗ Branch 554 not taken.
✗ Branch 555 not taken.
✗ Branch 556 not taken.
✗ Branch 557 not taken.
✗ Branch 558 not taken.
✗ Branch 559 not taken.
✗ Branch 560 not taken.
✗ Branch 561 not taken.
✗ Branch 562 not taken.
✗ Branch 563 not taken.
✗ Branch 564 not taken.
✗ Branch 565 not taken.
✗ Branch 566 not taken.
✗ Branch 567 not taken.
✗ Branch 568 not taken.
✗ Branch 569 not taken.
✗ Branch 570 not taken.
✗ Branch 571 not taken.
✗ Branch 572 not taken.
✗ Branch 573 not taken.
✗ Branch 574 not taken.
✗ Branch 575 not taken.
✗ Branch 576 not taken.
✗ Branch 577 not taken.
✗ Branch 578 not taken.
✗ Branch 579 not taken.
✗ Branch 580 not taken.
✗ Branch 581 not taken.
✗ Branch 582 not taken.
✗ Branch 583 not taken.
✗ Branch 584 not taken.
✗ Branch 585 not taken.
✗ Branch 586 not taken.
✗ Branch 587 not taken.
✗ Branch 588 not taken.
✗ Branch 589 not taken.
✗ Branch 590 not taken.
✗ Branch 591 not taken.
✗ Branch 592 not taken.
✗ Branch 593 not taken.
✗ Branch 594 not taken.
✗ Branch 595 not taken.
✗ Branch 596 not taken.
✗ Branch 597 not taken.
✗ Branch 598 not taken.
✗ Branch 599 not taken.
✗ Branch 600 not taken.
✗ Branch 601 not taken.
✗ Branch 602 not taken.
✗ Branch 603 not taken.
✗ Branch 604 not taken.
✗ Branch 605 not taken.
✗ Branch 606 not taken.
✓ Branch 607 taken 531793827 times.
✗ Branch 608 not taken.
✓ Branch 609 taken 43783163 times.
✓ Branch 610 taken 477697 times.
✓ Branch 611 taken 497243 times.
✓ Branch 612 taken 2779 times.
✓ Branch 613 taken 97670 times.
✗ Branch 614 not taken.
✓ Branch 615 taken 283431 times.
✓ Branch 616 taken 14290 times.
✗ Branch 617 not taken.
✓ Branch 618 taken 5110 times.
✗ Branch 619 not taken.
✓ Branch 620 taken 952 times.
✗ Branch 621 not taken.
✗ Branch 622 not taken.
✗ Branch 623 not taken.
✗ Branch 624 not taken.
✓ Branch 625 taken 388698 times.
✗ Branch 626 not taken.
✓ Branch 627 taken 277656 times.
✓ Branch 628 taken 93759 times.
✓ Branch 629 taken 93760 times.
✓ Branch 630 taken 93772 times.
✓ Branch 631 taken 93778 times.
✗ Branch 632 not taken.
✗ Branch 633 not taken.
✗ Branch 634 not taken.
✗ Branch 635 not taken.
✗ Branch 636 not taken.
✗ Branch 637 not taken.
✗ Branch 638 not taken.
✓ Branch 639 taken 1121819 times.
✗ Branch 640 not taken.
✗ Branch 641 not taken.
✗ Branch 642 not taken.
✗ Branch 643 not taken.
✗ Branch 644 not taken.
✗ Branch 645 not taken.
✗ Branch 646 not taken.
✗ Branch 647 not taken.
✗ Branch 648 not taken.
✗ Branch 649 not taken.
✗ Branch 650 not taken.
✓ Branch 651 taken 2 times.
✗ Branch 652 not taken.
✗ Branch 653 not taken.
✗ Branch 654 not taken.
✗ Branch 655 not taken.
✗ Branch 656 not taken.
✗ Branch 657 not taken.
✗ Branch 658 not taken.
✗ Branch 659 not taken.
✗ Branch 660 not taken.
✗ Branch 661 not taken.
✗ Branch 662 not taken.
✗ Branch 663 not taken.
✗ Branch 664 not taken.
✗ Branch 665 not taken.
✗ Branch 666 not taken.
✗ Branch 667 not taken.
✗ Branch 668 not taken.
✗ Branch 669 not taken.
✗ Branch 670 not taken.
✗ Branch 671 not taken.
✗ Branch 672 not taken.
✗ Branch 673 not taken.
✗ Branch 674 not taken.
✗ Branch 675 not taken.
✗ Branch 676 not taken.
✗ Branch 677 not taken.
✗ Branch 678 not taken.
✓ Branch 679 taken 182 times.
✗ Branch 680 not taken.
✗ Branch 681 not taken.
✗ Branch 682 not taken.
✗ Branch 683 not taken.
✗ Branch 684 not taken.
✗ Branch 685 not taken.
✗ Branch 686 not taken.
✗ Branch 687 not taken.
✓ Branch 688 taken 2760 times.
✗ Branch 689 not taken.
✗ Branch 690 not taken.
✗ Branch 691 not taken.
✗ Branch 692 not taken.
✗ Branch 693 not taken.
✗ Branch 694 not taken.
✗ Branch 695 not taken.
✗ Branch 696 not taken.
✗ Branch 697 not taken.
✓ Branch 698 taken 94 times.
✗ Branch 699 not taken.
✓ Branch 700 taken 13 times.
✗ Branch 701 not taken.
✗ Branch 702 not taken.
✗ Branch 703 not taken.
✗ Branch 704 not taken.
✗ Branch 705 not taken.
✓ Branch 706 taken 9786 times.
✓ Branch 707 taken 429 times.
✓ Branch 708 taken 885 times.
✓ Branch 709 taken 4922 times.
✓ Branch 710 taken 71308 times.
✗ Branch 711 not taken.
✗ Branch 712 not taken.
✗ Branch 713 not taken.
✗ Branch 714 not taken.
✓ Branch 715 taken 1104 times.
✓ Branch 716 taken 44193 times.
✗ Branch 717 not taken.
✗ Branch 718 not taken.
✗ Branch 719 not taken.
✓ Branch 720 taken 4 times.
✗ Branch 721 not taken.
✗ Branch 722 not taken.
✗ Branch 723 not taken.
✗ Branch 724 not taken.
✓ Branch 725 taken 39294 times.
✗ Branch 726 not taken.
✗ Branch 727 not taken.
✗ Branch 728 not taken.
✗ Branch 729 not taken.
✗ Branch 730 not taken.
✗ Branch 731 not taken.
✗ Branch 732 not taken.
✓ Branch 733 taken 370 times.
✗ Branch 734 not taken.
✗ Branch 735 not taken.
✓ Branch 736 taken 9 times.
✗ Branch 737 not taken.
✗ Branch 738 not taken.
✗ Branch 739 not taken.
✗ Branch 740 not taken.
✗ Branch 741 not taken.
✗ Branch 742 not taken.
✓ Branch 743 taken 28 times.
✗ Branch 744 not taken.
✗ Branch 745 not taken.
✗ Branch 746 not taken.
✗ Branch 747 not taken.
✓ Branch 748 taken 24 times.
✓ Branch 749 taken 24 times.
✗ Branch 750 not taken.
✗ Branch 751 not taken.
✓ Branch 752 taken 24 times.
✗ Branch 753 not taken.
✗ Branch 754 not taken.
✗ Branch 755 not taken.
✗ Branch 756 not taken.
✗ Branch 757 not taken.
✗ Branch 758 not taken.
✗ Branch 759 not taken.
✗ Branch 760 not taken.
✗ Branch 761 not taken.
✗ Branch 762 not taken.
✗ Branch 763 not taken.
✗ Branch 764 not taken.
✗ Branch 765 not taken.
✗ Branch 766 not taken.
✗ Branch 767 not taken.
✗ Branch 768 not taken.
✗ Branch 769 not taken.
✗ Branch 770 not taken.
✗ Branch 771 not taken.
✗ Branch 772 not taken.
✗ Branch 773 not taken.
✗ Branch 774 not taken.
✗ Branch 775 not taken.
✗ Branch 776 not taken.
✗ Branch 777 not taken.
✗ Branch 778 not taken.
✗ Branch 779 not taken.
✗ Branch 780 not taken.
✗ Branch 781 not taken.
✗ Branch 782 not taken.
✗ Branch 783 not taken.
✗ Branch 784 not taken.
✗ Branch 785 not taken.
✗ Branch 786 not taken.
✗ Branch 787 not taken.
✗ Branch 788 not taken.
✗ Branch 789 not taken.
✗ Branch 790 not taken.
✗ Branch 791 not taken.
✗ Branch 792 not taken.
✗ Branch 793 not taken.
✗ Branch 794 not taken.
✗ Branch 795 not taken.
✗ Branch 796 not taken.
✗ Branch 797 not taken.
✗ Branch 798 not taken.
✗ Branch 799 not taken.
✗ Branch 800 not taken.
✗ Branch 801 not taken.
✗ Branch 802 not taken.
✗ Branch 803 not taken.
✗ Branch 804 not taken.
✗ Branch 805 not taken.
✗ Branch 806 not taken.
✗ Branch 807 not taken.
✗ Branch 808 not taken.
✗ Branch 809 not taken.
✗ Branch 810 not taken.
✗ Branch 811 not taken.
✗ Branch 812 not taken.
✗ Branch 813 not taken.
✗ Branch 814 not taken.
✗ Branch 815 not taken.
✗ Branch 816 not taken.
✗ Branch 817 not taken.
✗ Branch 818 not taken.
✗ Branch 819 not taken.
✗ Branch 820 not taken.
✗ Branch 821 not taken.
✗ Branch 822 not taken.
✗ Branch 823 not taken.
✗ Branch 824 not taken.
✗ Branch 825 not taken.
✗ Branch 826 not taken.
✗ Branch 827 not taken.
✗ Branch 828 not taken.
✗ Branch 829 not taken.
✗ Branch 830 not taken.
✗ Branch 831 not taken.
✗ Branch 832 not taken.
✗ Branch 833 not taken.
✗ Branch 834 not taken.
✗ Branch 835 not taken.
✗ Branch 836 not taken.
✗ Branch 837 not taken.
✗ Branch 838 not taken.
✗ Branch 839 not taken.
✗ Branch 840 not taken.
✗ Branch 841 not taken.
✗ Branch 842 not taken.
✗ Branch 843 not taken.
✗ Branch 844 not taken.
✗ Branch 845 not taken.
✗ Branch 846 not taken.
✗ Branch 847 not taken.
✗ Branch 848 not taken.
✗ Branch 849 not taken.
✗ Branch 850 not taken.
✗ Branch 851 not taken.
✗ Branch 852 not taken.
✗ Branch 853 not taken.
✗ Branch 854 not taken.
✗ Branch 855 not taken.
✗ Branch 856 not taken.
✗ Branch 857 not taken.
✗ Branch 858 not taken.
✗ Branch 859 not taken.
✗ Branch 860 not taken.
✗ Branch 861 not taken.
✗ Branch 862 not taken.
✗ Branch 863 not taken.
✗ Branch 864 not taken.
✗ Branch 865 not taken.
✗ Branch 866 not taken.
✗ Branch 867 not taken.
✗ Branch 868 not taken.
✗ Branch 869 not taken.
✗ Branch 870 not taken.
✗ Branch 871 not taken.
✗ Branch 872 not taken.
✗ Branch 873 not taken.
✗ Branch 874 not taken.
✗ Branch 875 not taken.
✗ Branch 876 not taken.
✗ Branch 877 not taken.
✗ Branch 878 not taken.
✗ Branch 879 not taken.
✗ Branch 880 not taken.
✗ Branch 881 not taken.
✗ Branch 882 not taken.
✗ Branch 883 not taken.
✗ Branch 884 not taken.
✗ Branch 885 not taken.
✗ Branch 886 not taken.
✗ Branch 887 not taken.
✗ Branch 888 not taken.
✗ Branch 889 not taken.
✗ Branch 890 not taken.
✗ Branch 891 not taken.
✗ Branch 892 not taken.
✗ Branch 893 not taken.
✗ Branch 894 not taken.
✗ Branch 895 not taken.
✗ Branch 896 not taken.
✗ Branch 897 not taken.
✗ Branch 898 not taken.
✗ Branch 899 not taken.
✗ Branch 900 not taken.
✗ Branch 901 not taken.
✗ Branch 902 not taken.
✗ Branch 903 not taken.
✗ Branch 904 not taken.
✗ Branch 905 not taken.
✗ Branch 906 not taken.
✗ Branch 907 not taken.
✗ Branch 908 not taken.
✗ Branch 909 not taken.
✗ Branch 910 not taken.
✗ Branch 911 not taken.
✗ Branch 912 not taken.
✗ Branch 913 not taken.
✗ Branch 914 not taken.
✗ Branch 915 not taken.
✗ Branch 916 not taken.
✗ Branch 917 not taken.
✗ Branch 918 not taken.
✗ Branch 919 not taken.
✗ Branch 920 not taken.
✗ Branch 921 not taken.
✗ Branch 922 not taken.
✗ Branch 923 not taken.
✗ Branch 924 not taken.
✗ Branch 925 not taken.
✗ Branch 926 not taken.
✗ Branch 927 not taken.
✗ Branch 928 not taken.
✗ Branch 929 not taken.
✗ Branch 930 not taken.
✗ Branch 931 not taken.
✗ Branch 932 not taken.
✗ Branch 933 not taken.
✗ Branch 934 not taken.
✗ Branch 935 not taken.
✗ Branch 936 not taken.
✗ Branch 937 not taken.
✗ Branch 938 not taken.
✗ Branch 939 not taken.
✗ Branch 940 not taken.
✗ Branch 941 not taken.
✗ Branch 942 not taken.
✗ Branch 943 not taken.
✗ Branch 944 not taken.
✗ Branch 945 not taken.
✗ Branch 946 not taken.
✗ Branch 947 not taken.
✗ Branch 948 not taken.
✗ Branch 949 not taken.
✗ Branch 950 not taken.
✗ Branch 951 not taken.
✗ Branch 952 not taken.
✗ Branch 953 not taken.
✗ Branch 954 not taken.
✗ Branch 955 not taken.
✗ Branch 956 not taken.
✗ Branch 957 not taken.
✓ Branch 958 taken 646324090 times.
✗ Branch 959 not taken.
✗ Branch 960 not taken.
✗ Branch 961 not taken.
✗ Branch 962 not taken.
✗ Branch 963 not taken.
✗ Branch 964 not taken.
✗ Branch 965 not taken.
✗ Branch 966 not taken.
✗ Branch 967 not taken.
✗ Branch 968 not taken.
1622645979 switch(arg)
10620 {
10621 ///----------------------------------------------------------------------------------------------------//
10622 //FFC Variables
10623 case DATA:
10624
1/2
✓ Branch 0 taken 4499468 times.
✗ Branch 1 not taken.
4499468 if (auto ffc = ResolveFFC(ri->ffcref))
10625 {
10626 4499468 zc_ffc_set(*ffc, vbound(value/10000,0,MAXCOMBOS-1));
10627 4499468 }
10628 4499468 break;
10629
10630 case FFSCRIPT:
10631
1/2
✓ Branch 0 taken 14116 times.
✗ Branch 1 not taken.
14116 if (auto ffc = ResolveFFC(ri->ffcref))
10632 {
10633 14116 ffc->script = vbound(value/10000, 0, NUMSCRIPTFFC-1);
10634
2/2
✓ Branch 0 taken 225856 times.
✓ Branch 1 taken 14116 times.
239972 for(int32_t i=0; i<16; i++)
10635 225856 ffc->miscellaneous[i] = 0;
10636
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14116 times.
14116 if (get_qr(qr_CLEARINITDONSCRIPTCHANGE))
10637 {
10638
2/2
✓ Branch 0 taken 112928 times.
✓ Branch 1 taken 14116 times.
127044 for(int32_t i=0; i<8; i++)
10639 112928 ffc->initd[i] = 0;
10640 14116 }
10641 14116 on_reassign_script_engine_data(ScriptType::FFC, ffc->index);
10642 14116 }
10643 14116 break;
10644
10645
10646 case FCSET:
10647
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2047856 times.
2047856 if (auto ffc = ResolveFFC(ri->ffcref))
10648 2047856 ffc->cset = (value/10000)&15;
10649 2047856 break;
10650
10651 case DELAY:
10652
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 3629 times.
3675 if (auto ffc = ResolveFFC(ri->ffcref))
10653 3629 ffc->delay = value/10000;
10654 3675 break;
10655
10656 case FX:
10657
1/2
✓ Branch 0 taken 2299966 times.
✗ Branch 1 not taken.
2299966 if (auto ffc = ResolveFFC(ri->ffcref))
10658 2299966 ffc->x = zslongToFix(value);
10659 2299966 break;
10660
10661 case FY:
10662
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2299127 times.
2299127 if (auto ffc = ResolveFFC(ri->ffcref))
10663 2299127 ffc->y=zslongToFix(value);
10664 2299127 break;
10665
10666 case XD:
10667
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 13867 times.
13913 if (auto ffc = ResolveFFC(ri->ffcref))
10668 13867 ffc->vx=zslongToFix(value);
10669 13913 break;
10670
10671 case YD:
10672
2/2
✓ Branch 0 taken 14145 times.
✓ Branch 1 taken 46 times.
14191 if (auto ffc = ResolveFFC(ri->ffcref))
10673 14145 ffc->vy=zslongToFix(value);
10674 14191 break;
10675
10676 case FFCID:
10677 break;
10678
10679 case XD2:
10680
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 14275 times.
14321 if (auto ffc = ResolveFFC(ri->ffcref))
10681 14275 ffc->ax=zslongToFix(value);
10682 14321 break;
10683
10684 case YD2:
10685
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 15983 times.
16029 if (auto ffc = ResolveFFC(ri->ffcref))
10686 15983 ffc->ay=zslongToFix(value);
10687 16029 break;
10688
10689 case FFCWIDTH:
10690
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 4099 times.
4145 if (auto ffc = ResolveFFC(ri->ffcref))
10691 4099 ffc->hit_width = (value/10000);
10692 4145 break;
10693
10694 case FFCHEIGHT:
10695
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 4101 times.
4147 if (auto ffc = ResolveFFC(ri->ffcref))
10696 4101 ffc->hit_height = (value/10000);
10697 4147 break;
10698
10699 case FFTWIDTH:
10700
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13890 times.
13890 if (auto ffc = ResolveFFC(ri->ffcref))
10701 13890 ffc->txsz = vbound(value/10000, 1, 4);
10702 13890 break;
10703
10704 case FFTHEIGHT:
10705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13913 times.
13913 if (auto ffc = ResolveFFC(ri->ffcref))
10706 13913 ffc->tysz = vbound(value/10000, 1, 4);
10707 13913 break;
10708
10709 case FFCLAYER:
10710 if (auto ffc = ResolveFFC(ri->ffcref))
10711 ffc->layer = vbound(value/10000, 0, 7);
10712 break;
10713
10714 case FFLINK:
10715
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 763 times.
809 if (auto ffc = ResolveFFC(ri->ffcref))
10716 763 (ffc->link)=vbound(value/10000, 0, MAXFFCS-1); // Allow "ffc->Link = 0" to unlink ffc.
10717 //0 is none, setting this before made it impssible to clear it. -Z
10718 809 break;
10719
10720 case FFCLASTCHANGERX:
10721 if (auto ffc = ResolveFFC(ri->ffcref) )
10722 ffc->changer_x=vbound(zslongToFix(value).getInt(),-32768, 32767);
10723 break;
10724
10725 case FFCLASTCHANGERY:
10726 if (auto ffc = ResolveFFC(ri->ffcref) )
10727 ffc->changer_y=vbound(zslongToFix(value).getInt(),-32768, 32767);
10728 break;
10729
10730
10731
10732 ///----------------------------------------------------------------------------------------------------//
10733 //Hero's Variables
10734 case LINKX:
10735 {
10736
2/2
✓ Branch 0 taken 23258 times.
✓ Branch 1 taken 454439 times.
477697 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
10737 {
10738 23258 Hero.setXfix(zslongToFix(value));
10739 23258 }
10740 else
10741 {
10742 454439 Hero.setX(value/10000);
10743 }
10744 }
10745 477697 break;
10746
10747 case LINKCSET:
10748 {
10749 Hero.cs = value/10000;
10750 break;
10751 }
10752 case LINKY:
10753 {
10754
2/2
✓ Branch 0 taken 22483 times.
✓ Branch 1 taken 474760 times.
497243 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
10755 {
10756 22483 Hero.setYfix(zslongToFix(value));
10757 22483 }
10758 else
10759 {
10760 474760 Hero.setY(value/10000);
10761 }
10762 }
10763 497243 break;
10764
10765 case LINKZ:
10766 {
10767
2/2
✓ Branch 0 taken 2775 times.
✓ Branch 1 taken 4 times.
2779 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
10768 {
10769 2775 Hero.setZfix(zslongToFix(value));
10770 2775 }
10771 else
10772 {
10773 4 Hero.setZ(value/10000);
10774 }
10775 }
10776 2779 break;
10777
10778 case LINKJUMP:
10779 76581 Hero.setJump(zslongToFix(value));
10780 76581 break;
10781
10782 case HEROFAKEJUMP:
10783 Hero.setFakeFall(zslongToFix(value) * -100);
10784 break;
10785
10786 case LINKDIR:
10787 {
10788 //Hero->setDir() calls reset_hookshot(), which removes the sword sprite.. O_o
10789
3/4
✓ Branch 0 taken 95484 times.
✓ Branch 1 taken 2186 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 95484 times.
97670 if(Hero.getAction() == attacking || Hero.getAction() == sideswimattacking) Hero.dir = (value/10000);
10790 95484 else Hero.setDir(value/10000);
10791
10792 97670 break;
10793 }
10794
10795 case LINKHITDIR:
10796 2220 Hero.setHitDir(value / 10000);
10797 2220 break;
10798
10799 case LINKGRAVITY:
10800 if(value)
10801 Hero.moveflags |= move_obeys_grav;
10802 else
10803 Hero.moveflags &= ~move_obeys_grav;
10804 break;
10805
10806 case HERONOSTEPFORWARD:
10807 FFCore.nostepforward = ( (value) ? 1 : 0 );
10808 break;
10809
10810 case LINKHP:
10811
6/6
✓ Branch 0 taken 177818 times.
✓ Branch 1 taken 105613 times.
✓ Branch 2 taken 283260 times.
✓ Branch 3 taken 171 times.
✓ Branch 4 taken 177647 times.
✓ Branch 5 taken 105613 times.
283431 game->set_life(zc_max(0, zc_min(value/10000,game->get_maxlife())));
10812 283431 break;
10813
10814 case LINKMP:
10815
6/6
✓ Branch 0 taken 6601 times.
✓ Branch 1 taken 7689 times.
✓ Branch 2 taken 14271 times.
✓ Branch 3 taken 19 times.
✓ Branch 4 taken 6582 times.
✓ Branch 5 taken 7689 times.
14290 game->set_magic(zc_max(0, zc_min(value/10000,game->get_maxmagic())));
10816 14290 break;
10817
10818 case LINKMAXHP:
10819 60 game->set_maxlife(value/10000);
10820 60 break;
10821
10822 case LINKMAXMP:
10823 game->set_maxmagic(value/10000);
10824 break;
10825
10826 case LINKACTION:
10827 {
10828 5110 int32_t act = value / 10000;
10829
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5110 times.
5110 switch(act)
10830 {
10831 case hookshotout:
10832 case stunned:
10833 case ispushing:
10834 FFCore.setHeroAction(act);
10835 break;
10836 default:
10837 5110 Hero.setAction((actiontype)(act));
10838 5110 }
10839 //Protect from writing illegal actions to Hero's raw variable.
10840 //in the future, we can move all scripted actions that are not possible
10841 //to set in ZC into this mechanic. -Z
10842 5110 break;
10843 }
10844
10845 case HEROHEALTHBEEP:
10846 {
10847 int32_t beep = vbound((value/10000),-4, 255);
10848 //-2 suspends system control of stopping the sound
10849 //-3 suspends system control of stopping the sound AND suspends
10850 // system control over starting or playing it.
10851 heart_beep_timer = beep;
10852 if ( heart_beep_timer > -1 )
10853 {
10854 cont_sfx(QMisc.miscsfx[sfxLOWHEART]);
10855 }
10856 else
10857 {
10858 stop_sfx(QMisc.miscsfx[sfxLOWHEART]);
10859 }
10860 break;
10861 }
10862
10863 case LINKHELD:
10864 48 Hero.setHeldItem(vbound(value/10000,0,MAXITEMS-1));
10865 48 break;
10866
10867 case HEROSTEPRATE:
10868
1/2
✓ Branch 0 taken 952 times.
✗ Branch 1 not taken.
952 if(!get_qr(qr_NEW_HERO_MOVEMENT))
10869 {
10870 Z_scripterrlog("To use '%s', you must %s the quest rule '%s'.", "Hero->Step", "enable", "New Hero Movement");
10871 }
10872
1/2
✓ Branch 0 taken 952 times.
✗ Branch 1 not taken.
952 Hero.setStepRate(zc_max(value/10000,0));
10873
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 952 times.
952 if(!get_qr(qr_SCRIPT_WRITING_HEROSTEP_DOESNT_CARRY_OVER))
10874 952 zinit.heroStep = Hero.getStepRate();
10875 952 break;
10876 case HEROSHOVEOFFSET:
10877 if(!get_qr(qr_NEW_HERO_MOVEMENT2))
10878 Z_scripterrlog("To use 'Hero->ShoveOffset', you must enable the quest rule 'Newer Hero Movement'.");
10879 Hero.shove_offset = vbound(zslongToFix(value),16_zf,0_zf);
10880 if(!get_qr(qr_SCRIPT_WRITING_HEROSTEP_DOESNT_CARRY_OVER))
10881 zinit.shove_offset = Hero.shove_offset;
10882 break;
10883
10884 case LINKEQUIP:
10885 {
10886 if ( FFCore.getQuestHeaderInfo(vZelda) == 0x250 && FFCore.getQuestHeaderInfo(vBuild) < 33 )
10887 {
10888 break;
10889 }
10890 //int32_t seta = (value/10000) >> 8; int32_t setb = value/10000) & 0xFF;
10891 int32_t setb = ((value/10000)&0xFF00)>>8, seta = (value/10000)&0xFF;
10892 seta = vbound(seta,-1,255);
10893 setb = vbound(setb,-1,255);
10894
10895 Awpn = seta;
10896 game->awpn = 255;
10897 game->forced_awpn = seta;
10898 game->items_off[seta] = 0;
10899 directItemA = seta;
10900
10901 Bwpn = setb;
10902 game->bwpn = 255;
10903 game->forced_bwpn = setb;
10904 game->items_off[setb] = 0;
10905 directItemB = setb;
10906 break;
10907 }
10908
10909
10910 case SETITEMSLOT:
10911 {
10912 //ri->d[rINDEX2] = 1st arg
10913 //ri->d[rINDEX] = 2nd arg
10914 //value = third arg
10915 //int32_t item, int32_t slot, int32_t force
10916 int32_t itm = ri->d[rINDEX]/10000;
10917 itm = vbound(itm, -1, 255);
10918
10919 int32_t slot = ri->d[rINDEX2]/10000;
10920 int32_t force = ri->d[rEXP1]/10000;
10921
10922 //If we add more item buttons, slot should be an int32_t
10923 //and force shuld be an int32_t
10924
10925 /*
10926 For zScript,
10927 const int32_t ITM_REQUIRE_NONE = 0
10928 const int32_t ITM_REQUIRE_INVENTORY = 1
10929 const int32_t ITM_REQUIRE_A_SLOT_RULE = 2
10930 //Combine as flags
10931 */
10932 if ( force == 0 )
10933 {
10934 switch(slot)
10935 {
10936 case 0: //b
10937 Bwpn = itm;
10938 game->items_off[itm] = 0;
10939 game->bwpn = 255;
10940 game->forced_bwpn = itm;
10941 directItemB = itm;
10942 break;
10943
10944 case 1: //a
10945 Awpn = itm;
10946 game->items_off[itm] = 0;
10947 game->awpn = 255;
10948 game->forced_awpn = itm;
10949 directItemA = itm;
10950 break;
10951
10952 case 2: //x
10953 Xwpn = itm;
10954 game->items_off[itm] = 0;
10955 game->xwpn = 255;
10956 game->forced_xwpn = itm;
10957 directItemX = itm;
10958 break;
10959
10960 case 3: //y
10961 Ywpn = itm;
10962 game->items_off[itm] = 0;
10963 game->ywpn = 255;
10964 game->forced_ywpn = itm;
10965 directItemX = itm;
10966 break;
10967 }
10968 }
10969 else if ( force == 1 )
10970 {
10971 if (game->item[itm])
10972 {
10973 switch(slot)
10974 {
10975 case 0: //b
10976 Bwpn = itm;
10977 game->items_off[itm] = 0;
10978 game->bwpn = 255;
10979 game->forced_bwpn = itm;
10980 directItemB = itm;
10981 break;
10982
10983 case 1: //a
10984 Awpn = itm;
10985 game->items_off[itm] = 0;
10986 game->awpn = 255;
10987 game->forced_awpn = itm;
10988 directItemA = itm;
10989 break;
10990
10991 case 2: //x
10992 Xwpn = itm;
10993 game->items_off[itm] = 0;
10994 game->xwpn = 255;
10995 game->forced_xwpn = itm;
10996 directItemX = itm;
10997 break;
10998
10999 case 3: //y
11000 Ywpn = itm;
11001 game->items_off[itm] = 0;
11002 game->ywpn = 255;
11003 game->forced_ywpn = itm;
11004 directItemY = itm;
11005 break;
11006 }
11007 }
11008 }
11009 else if ( force == 2 )
11010 {
11011 switch(slot)
11012 {
11013 case 0: //b
11014 Bwpn = itm;
11015 game->items_off[itm] = 0;
11016 game->bwpn = 255;
11017 game->forced_bwpn = itm;
11018 directItemB = itm;
11019 break;
11020
11021 case 1: //a
11022 if (get_qr(qr_SELECTAWPN))
11023 {
11024 Awpn = itm;
11025 game->items_off[itm] = 0;
11026 game->awpn = 255;
11027 game->forced_awpn = itm;
11028 directItemA = itm;
11029 }
11030 break;
11031
11032 case 2: //x
11033 Xwpn = itm;
11034 game->items_off[itm] = 0;
11035 game->xwpn = 255;
11036 game->forced_xwpn = itm;
11037 directItemX = itm;
11038 break;
11039
11040 case 3: //y
11041 Ywpn = itm;
11042 game->items_off[itm] = 0;
11043 game->ywpn = 255;
11044 game->forced_ywpn = itm;
11045 directItemY = itm;
11046 break;
11047 }
11048 }
11049 else if ( force == 3 ) //Flag ITM_REQUIRE_INVENTORY + ITM_REQUIRE_SLOT_A_RULE
11050 {
11051 if ( game->item[itm] )
11052 {
11053 switch(slot)
11054 {
11055 case 0: //b
11056 Bwpn = itm;
11057 game->items_off[itm] = 0;
11058 game->bwpn = 255;
11059 game->forced_bwpn = itm;
11060 directItemB = itm;
11061 break;
11062
11063 case 1: //a
11064 if (get_qr(qr_SELECTAWPN))
11065 {
11066 Awpn = itm;
11067 game->items_off[itm] = 0;
11068 game->awpn = 255;
11069 game->forced_awpn = itm;
11070 directItemA = itm;
11071 }
11072 break;
11073
11074 case 2: //x
11075 Xwpn = itm;
11076 game->items_off[itm] = 0;
11077 game->xwpn = 255;
11078 game->forced_xwpn = itm;
11079 directItemX = itm;
11080 break;
11081
11082 case 3: //y
11083 Ywpn = itm;
11084 game->items_off[itm] = 0;
11085 game->ywpn = 255;
11086 game->forced_ywpn = itm;
11087 directItemY = itm;
11088 break;
11089 }
11090 }
11091 }
11092 }
11093 break;
11094
11095 case LINKINVIS:
11096 837 Hero.setDontDraw((value ? 2 : 0));
11097 837 break;
11098
11099 case LINKINVINC:
11100 2288 Hero.scriptcoldet=(value/10000);
11101 2288 break;
11102
11103 case LINKENGINEANIMATE:
11104 Hero.do_animation=value;
11105 break;
11106
11107 case LINKSWORDJINX:
11108 718 Hero.setSwordClk(value/10000);
11109 718 break;
11110
11111 case LINKITEMJINX:
11112 5878 Hero.setItemClk(value/10000);
11113 5878 break;
11114
11115 case LINKDRUNK:
11116 1 Hero.setDrunkClock(value/10000);
11117 1 break;
11118
11119 case LINKHXOFS:
11120 (Hero.hxofs)=(zfix)(value/10000);
11121 break;
11122
11123 case LINKROTATION:
11124 if ( get_qr(qr_OLDSPRITEDRAWS) )
11125 {
11126 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
11127 break;
11128 }
11129 (Hero.rotation)=(value/10000);
11130 break;
11131
11132 case LINKSCALE:
11133 {
11134 if ( get_qr(qr_OLDSPRITEDRAWS) )
11135 {
11136 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
11137 break;
11138 }
11139 (Hero.scale)=(value/100.0);
11140 break;
11141 }
11142
11143 case LINKHYOFS:
11144 (Hero.hyofs)=(zfix)(value/10000);
11145 break;
11146
11147 case LINKXOFS:
11148 26326 (Hero.xofs)=(zfix)(value/10000);
11149 26326 break;
11150
11151 case LINKYOFS:
11152
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 388698 times.
388698 (Hero.yofs)=(zfix)(value/10000)+(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset);
11153 388698 break;
11154 case HEROTOTALDYOFFS:
11155 break; //READ-ONLY
11156
11157 case HEROSHADOWXOFS:
11158 (Hero.shadowxofs)=(zfix)(value/10000);
11159 break;
11160
11161 case HEROSHADOWYOFS:
11162 (Hero.shadowyofs)=(zfix)(value/10000);
11163 break;
11164
11165 case LINKZOFS:
11166 (Hero.zofs)=(zfix)(value/10000);
11167 break;
11168
11169 case LINKHXSZ:
11170 (Hero.hit_width)=(zfix)(value/10000);
11171 break;
11172
11173 case LINKHYSZ:
11174 (Hero.hit_height)=(zfix)(value/10000);
11175 break;
11176
11177 case LINKHZSZ:
11178 (Hero.hzsz)=(zfix)(value/10000);
11179 break;
11180
11181 case LINKTXSZ:
11182 (Hero.txsz)=(zfix)(value/10000);
11183 break;
11184
11185 case LINKTYSZ:
11186 (Hero.tysz)=(zfix)(value/10000);
11187 break;
11188
11189 case LINKTILE:
11190 (Hero.tile)=(zfix)(value/10000);
11191 break;
11192
11193 case LINKFLIP:
11194 (Hero.flip)=(zfix)(value/10000);
11195 break;
11196
11197
11198
11199 case LINKINVFRAME:
11200 3 Hero.setHClk( (int32_t)vbound((value/10000), 0, 214747) );
11201 3 break;
11202
11203 case LINKCANFLICKER:
11204 277656 Hero.setCanFlicker((value/10000)?1:0);
11205 277656 break;
11206
11207 case LINKHURTSFX:
11208 277656 Hero.setHurtSFX( (int32_t)vbound((value/10000), 0, 255) );
11209 277656 break;
11210
11211
11212 case LINKITEMB:
11213 {
11214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93759 times.
93759 if ( value/10000 < -1 )
11215 {
11216 al_trace("Tried to write an invalid item ID to Hero->ItemB: %d\n",value/10000);
11217 break;
11218 }
11219
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93759 times.
93759 if ( value/10000 > MAXITEMS-1 )
11220 {
11221 al_trace("Tried to write an invalid item ID to Hero->ItemB: %d\n",value/10000);
11222 break;
11223 }
11224 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
11225
11226
2/2
✓ Branch 0 taken 93750 times.
✓ Branch 1 taken 9 times.
93759 if (Bwpn != (value/10000))
11227 {
11228 9 Bwpn = value/10000;
11229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(new_subscreen_active)
11230 9 new_subscreen_active->get_page_pos(Bwpn, game->bwpn);
11231 9 game->forced_bwpn = value/10000;
11232 9 game->items_off[value/10000] = 0;
11233 9 }
11234 93759 directItemB = value/10000;
11235 93759 break;
11236 }
11237
11238
11239 case LINKITEMA:
11240 {
11241
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93760 times.
93760 if ( value/10000 < -1 )
11242 {
11243 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemA: %d\n",value/10000);
11244 break;
11245 }
11246
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93760 times.
93760 if ( value/10000 > MAXITEMS-1 )
11247 {
11248 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemA: %d\n",value/10000);
11249 break;
11250 }
11251 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
11252
2/2
✓ Branch 0 taken 93752 times.
✓ Branch 1 taken 8 times.
93760 if (Awpn != (value/10000))
11253 {
11254 8 Awpn = value/10000;
11255
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(new_subscreen_active)
11256 8 new_subscreen_active->get_page_pos(Awpn, game->awpn);
11257 8 game->items_off[value/10000] = 0;
11258 8 game->forced_awpn = value/10000;
11259 8 }
11260 93760 directItemA = value/10000;
11261 93760 break;
11262 }
11263
11264 case LINKITEMX:
11265 {
11266
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93772 times.
93772 if ( value/10000 < -1 )
11267 {
11268 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemX: %d\n",value/10000);
11269 break;
11270 }
11271
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93772 times.
93772 if ( value/10000 > MAXITEMS-1 )
11272 {
11273 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemX: %d\n",value/10000);
11274 break;
11275 }
11276 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
11277
2/2
✓ Branch 0 taken 93739 times.
✓ Branch 1 taken 33 times.
93772 if (Xwpn != (value/10000))
11278 {
11279 33 Xwpn = value/10000;
11280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if(new_subscreen_active)
11281 33 new_subscreen_active->get_page_pos(Xwpn, game->xwpn);
11282 33 game->items_off[value/10000] = 0;
11283 33 game->forced_xwpn = value/10000;
11284 33 }
11285 93772 directItemX = value/10000;
11286 93772 break;
11287 }
11288 case LINKITEMY:
11289 {
11290
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93778 times.
93778 if ( value/10000 < -1 )
11291 {
11292 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemY: %d\n",value/10000);
11293 break;
11294 }
11295
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93778 times.
93778 if ( value/10000 > MAXITEMS-1 )
11296 {
11297 Z_scripterrlog("Tried to write an invalid item ID to Hero->ItemY: %d\n",value/10000);
11298 break;
11299 }
11300 //Hero->setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
11301
2/2
✓ Branch 0 taken 93735 times.
✓ Branch 1 taken 43 times.
93778 if (Ywpn != (value/10000))
11302 {
11303 43 Ywpn = value/10000;
11304
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if(new_subscreen_active)
11305 43 new_subscreen_active->get_page_pos(Ywpn, game->ywpn);
11306 43 game->items_off[value/10000] = 0;
11307 43 game->forced_ywpn = value/10000;
11308 43 }
11309 93778 directItemY = value/10000;
11310 93778 break;
11311 }
11312
11313
11314 case LINKEATEN:
11315 Hero.setEaten(value/10000);
11316 break;
11317 case LINKGRABBED:
11318 Hero.inwallm = value != 0;
11319 break;
11320 case HEROBUNNY:
11321 Hero.setBunnyClock(value/10000);
11322 break;
11323 case LINKPUSH:
11324 Hero.pushing = zc_max((value/10000),0);
11325 break;
11326 case LINKSTUN:
11327 290 Hero.setStunClock(value/10000);
11328 290 break;
11329 case LINKSCRIPTTILE:
11330 4859 script_hero_sprite=vbound((value/10000), -1, NEWMAXTILES-1);
11331 4859 break;
11332
11333 case HEROSCRIPTCSET:
11334 3652 script_hero_cset=vbound((value/10000), -1, 0xF);
11335 3652 break;
11336 case LINKSCRIPFLIP:
11337 2578 script_hero_flip=vbound((value/10000),-1,256);
11338 2578 break;
11339
11340 case GAMESETA:
11341 {
11342 //int32_t state = (ri->d[rINDEX2]/10000);
11343 //int32_t extend = (ri->d[rINDEX2]/10000);
11344 //int32_t dir = (ri->d[rINDEX]/10000);
11345 // Z_message("Trying to force-set the A-button item().\n");
11346 // Hero.setAButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
11347 }
11348 break;
11349
11350 case GAMESETB:
11351 {
11352 //int32_t state = (ri->d[rINDEX2]/10000);
11353 //int32_t extend = (ri->d[rINDEX2]/10000);
11354 //int32_t dir = (ri->d[rINDEX]/10000);
11355 // Z_message("Trying to force-set the A-button item().\n");
11356 // Hero.setBButtonItem(vbound((value/10000),0,(MAXITEMS-1)));
11357 }
11358 break;
11359
11360 //Set Hero Diagonal
11361 case LINKDIAG:
11362 Hero.setDiagMove(value?1:0);
11363 set_qr(qr_LTTPWALK, value?1:0);
11364 break;
11365
11366 //Set Hero Big Hitbox
11367 case LINKBIGHITBOX:
11368 Hero.setBigHitbox((value/10000)?1:0);
11369 set_qr(qr_LTTPCOLLISION, (value/10000)?1:0);
11370 break;
11371
11372 case LINKCLIMBING:
11373 Hero.setOnSideviewLadder(value!=0?true:false);
11374 break;
11375
11376 case HEROJUMPCOUNT:
11377 Hero.extra_jump_count = value/10000;
11378 break;
11379
11380 case HEROPULLCLK:
11381 Hero.pit_pullclk = value/10000;
11382 break;
11383 case HEROFALLCLK:
11384 {
11385 int32_t val = vbound(value/10000,0,70);
11386 if(val)
11387 Hero.setAction(falling);
11388 else if(Hero.action == falling)
11389 {
11390 Hero.setAction(none);
11391 }
11392 Hero.fallclk = val;
11393 break;
11394 }
11395 case HEROFALLCMB:
11396 Hero.fallCombo = vbound(value/10000,0,MAXCOMBOS-1);
11397 break;
11398 case HERODROWNCLK:
11399 {
11400 int32_t val = vbound(value/10000,0,70);
11401 if(val)
11402 {
11403 if (Hero.action != lavadrowning) Hero.setAction(drowning);
11404 }
11405 else if(Hero.action == drowning || Hero.action == lavadrowning)
11406 {
11407 Hero.setAction(none);
11408 }
11409 Hero.drownclk = val;
11410 break;
11411 }
11412 case HERODROWNCMB:
11413 Hero.drownCombo = vbound(value/10000,0,MAXCOMBOS-1);
11414 break;
11415 case HEROFAKEZ:
11416 {
11417 if ( get_qr(qr_SPRITEXY_IS_FLOAT) )
11418 {
11419 Hero.setFakeZfix(zslongToFix(value));
11420 }
11421 else
11422 {
11423 Hero.setFakeZ(value/10000);
11424 }
11425 }
11426 break;
11427
11428 case HEROSHIELDJINX:
11429 {
11430 Hero.shieldjinxclk = value / 10000;
11431 break;
11432 }
11433
11434 case CLOCKACTIVE:
11435 {
11436 4 Hero.setClock(watch=(value?true:false));
11437 4 break;
11438 }
11439
11440 case CLOCKCLK:
11441 clockclk = vbound((value/10000), 0, 214748);
11442 break;
11443
11444 case HERORESPAWNX:
11445 {
11446 zfix zx = zslongToFix(value);
11447 Hero.respawn_x = vbound(zx, 0_zf, 240_zf);
11448 break;
11449 }
11450
11451 case HERORESPAWNY:
11452 {
11453 zfix zy = zslongToFix(value);
11454 Hero.respawn_y = vbound(zy, 0_zf, 160_zf);
11455 break;
11456 }
11457
11458 case HERORESPAWNDMAP:
11459 {
11460 Hero.respawn_dmap = vbound(value/10000, 0, MAXDMAPS-1);
11461 break;
11462 }
11463
11464 case HERORESPAWNSCR:
11465 {
11466 Hero.respawn_scr = vbound(value/10000, 0, 0x7F);
11467 break;
11468 }
11469
11470
11471 case HEROSWITCHMAXTIMER:
11472 case HEROSWITCHTIMER:
11473 break; //read-only
11474
11475 case HEROIMMORTAL:
11476 {
11477 Hero.setImmortal(value/10000);
11478 break;
11479 }
11480
11481 case HEROCOYOTETIME:
11482 {
11483 auto v = value/10000;
11484 if(v < 0 || v > 65535) v = 65535;
11485 Hero.coyotetime = word(v);
11486 break;
11487 }
11488 case HEROLIFTEDWPN:
11489 {
11490 if(Hero.lift_wpn)
11491 {
11492 delete Hero.lift_wpn;
11493 Hero.lift_wpn = nullptr;
11494 }
11495 if(value)
11496 {
11497 if(weapon* wpn = checkLWpn(value))
11498 {
11499 if(wpn == Hero.lift_wpn) break;
11500 Hero.lift_wpn = wpn;
11501 if(Lwpns.find(wpn) > -1)
11502 Lwpns.remove(wpn);
11503 if(curScriptType == ScriptType::Lwpn && value == curScriptIndex)
11504 earlyretval = RUNSCRIPT_SELFREMOVE;
11505 }
11506 }
11507 break;
11508 }
11509 case HEROLIFTTIMER:
11510 {
11511 Hero.liftclk = value/10000;
11512 break;
11513 }
11514 case HEROLIFTMAXTIMER:
11515 {
11516 Hero.tliftclk = value/10000;
11517 break;
11518 }
11519 case HEROLIFTHEIGHT:
11520 {
11521 Hero.liftheight = zslongToFix(value);
11522 break;
11523 }
11524 case HEROHAMMERSTATE:
11525 {
11526 //readonly
11527 break;
11528 }
11529 case HEROFLICKERCOLOR:
11530 {
11531 Hero.flickercolor = value/10000;
11532 break;
11533 }
11534 case HEROFLICKERTRANSP:
11535 {
11536 Hero.flickertransp = value / 10000;
11537 break;
11538 }
11539 case HEROSCRICECMB:
11540 Hero.script_ice_combo = vbound(value/10000,-1,MAXCOMBOS); break;
11541 case HEROICEVX:
11542 Hero.ice_vx = zslongToFix(value); break;
11543 case HEROICEVY:
11544 Hero.ice_vy = zslongToFix(value); break;
11545 case HEROICEENTRYFRAMES:
11546 Hero.ice_entry_count = vbound(value/10000,0,255); break;
11547 case HEROICEENTRYMAXFRAMES:
11548 Hero.ice_entry_mcount = vbound(value/10000,0,255); break;
11549
11550
11551 ///----------------------------------------------------------------------------------------------------//
11552 //Input States
11553 case INPUTSTART:
11554 {
11555 1121819 control_state[6]=(value?true:false);
11556
2/2
✓ Branch 0 taken 1058724 times.
✓ Branch 1 taken 63095 times.
1121819 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[6]=false;
11557 1121819 break;
11558 }
11559
11560 case INPUTMAP:
11561 {
11562 646198 control_state[9]=(value?true:false);
11563
2/2
✓ Branch 0 taken 476961 times.
✓ Branch 1 taken 169237 times.
646198 if ( get_qr(qr_FIXDRUNKINPUTS) )
11564 169237 drunk_toggle_state[9]=false;
11565 646198 break;
11566 }
11567
11568 case INPUTUP:
11569 {
11570 298036 control_state[0]=(value?true:false);
11571
2/2
✓ Branch 0 taken 293445 times.
✓ Branch 1 taken 4591 times.
298036 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[0]=false;
11572 298036 break;
11573 }
11574
11575 case INPUTDOWN:
11576 {
11577 295303 control_state[1]=(value?true:false);
11578
2/2
✓ Branch 0 taken 290748 times.
✓ Branch 1 taken 4555 times.
295303 if ( get_qr(qr_FIXDRUNKINPUTS) )
11579 4555 drunk_toggle_state[1]=false;
11580 295303 break;
11581 }
11582
11583 case INPUTLEFT:
11584 {
11585 281941 control_state[2]=(value?true:false);
11586
2/2
✓ Branch 0 taken 277104 times.
✓ Branch 1 taken 4837 times.
281941 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[2]=false;
11587 281941 break;
11588 }
11589
11590 case INPUTRIGHT:
11591 {
11592 281894 control_state[3]=(value?true:false);
11593
2/2
✓ Branch 0 taken 277163 times.
✓ Branch 1 taken 4731 times.
281894 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[3]=false;
11594 281894 break;
11595 }
11596
11597 case INPUTA:
11598 {
11599 186826 control_state[4]=(value?true:false);
11600
2/2
✓ Branch 0 taken 142947 times.
✓ Branch 1 taken 43879 times.
186826 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[4]=false;
11601 186826 break;
11602 }
11603
11604 case INPUTB:
11605 {
11606 120700 control_state[5]=(value?true:false);
11607
2/2
✓ Branch 0 taken 116814 times.
✓ Branch 1 taken 3886 times.
120700 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[5]=false;
11608 120700 break;
11609 }
11610
11611 case INPUTL:
11612 {
11613 118163 control_state[7]=(value?true:false);
11614
2/2
✓ Branch 0 taken 116528 times.
✓ Branch 1 taken 1635 times.
118163 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[7]=false;
11615 118163 break;
11616 }
11617
11618 case INPUTR:
11619 {
11620 118214 control_state[8]=(value?true:false);
11621
2/2
✓ Branch 0 taken 116579 times.
✓ Branch 1 taken 1635 times.
118214 if ( get_qr(qr_FIXDRUNKINPUTS) ) drunk_toggle_state[8]=false;
11622 118214 break;
11623 }
11624
11625 case INPUTEX1:
11626 {
11627 262073 control_state[10]=(value?true:false);
11628 262073 break;
11629 }
11630
11631 case INPUTEX2:
11632 262073 control_state[11]=(value?true:false);
11633 262073 break;
11634
11635 case INPUTEX3:
11636 262073 control_state[12]=(value?true:false);
11637 262073 break;
11638
11639 case INPUTEX4:
11640 262073 control_state[13]=(value?true:false);
11641 262073 break;
11642
11643 case INPUTAXISUP:
11644 control_state[14]=(value?true:false);
11645 break;
11646
11647 case INPUTAXISDOWN:
11648 control_state[15]=(value?true:false);
11649 break;
11650
11651 case INPUTAXISLEFT:
11652 control_state[16]=(value?true:false);
11653 break;
11654
11655 case INPUTAXISRIGHT:
11656 control_state[17]=(value?true:false);
11657 break;
11658
11659 case INPUTPRESSSTART:
11660 1121819 button_press[6]=(value?true:false);
11661 1121819 break;
11662
11663 case INPUTPRESSMAP:
11664 646198 button_press[9]=(value?true:false);
11665 646198 break;
11666
11667 case INPUTPRESSUP:
11668 261563 button_press[0]=(value?true:false);
11669 261563 break;
11670
11671 case INPUTPRESSDOWN:
11672 261555 button_press[1]=(value?true:false);
11673 261555 break;
11674
11675 case INPUTPRESSLEFT:
11676 261628 button_press[2]=(value?true:false);
11677 261628 break;
11678
11679 case INPUTPRESSRIGHT:
11680 261662 button_press[3]=(value?true:false);
11681 261662 break;
11682
11683 case INPUTPRESSA:
11684 177542 button_press[4]=(value?true:false);
11685 177542 break;
11686
11687 case INPUTPRESSB:
11688 111830 button_press[5]=(value?true:false);
11689 111830 break;
11690
11691 case INPUTPRESSL:
11692 115219 button_press[7]=(value?true:false);
11693 115219 break;
11694
11695 case INPUTPRESSR:
11696 115270 button_press[8]=(value?true:false);
11697 115270 break;
11698
11699 case INPUTPRESSEX1:
11700 262073 button_press[10]=(value?true:false);
11701 262073 break;
11702
11703 case INPUTPRESSEX2:
11704 262073 button_press[11]=(value?true:false);
11705 262073 break;
11706
11707 case INPUTPRESSEX3:
11708 262073 button_press[12]=(value?true:false);
11709 262073 break;
11710
11711 case INPUTPRESSEX4:
11712 262073 button_press[13]=(value?true:false);
11713 262073 break;
11714
11715 case PRESSAXISUP:
11716 button_press[14]=(value?true:false);
11717 break;
11718
11719 case PRESSAXISDOWN:
11720 button_press[15]=(value?true:false);
11721 break;
11722
11723 case PRESSAXISLEFT:
11724 button_press[16]=(value?true:false);
11725 break;
11726
11727 case PRESSAXISRIGHT:
11728 button_press[17]=(value?true:false);
11729 break;
11730
11731 case INPUTMOUSEX:
11732 {
11733 auto [x, y] = rti_game.local_to_world(value/10000, mouse_y);
11734 position_mouse(x, y);
11735 break;
11736 }
11737
11738 case INPUTMOUSEY:
11739 {
11740 int32_t mousequakeoffset = 56+((int32_t)(zc::math::Sin((double)(quakeclk*int64_t(2)-frame))*4));
11741 int32_t tempoffset = (quakeclk > 0) ? mousequakeoffset : (get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset);
11742 auto [x, y] = rti_game.local_to_world(mouse_x, value/10000 + tempoffset);
11743 position_mouse(x, y);
11744 break;
11745 }
11746
11747 case INPUTMOUSEZ:
11748 position_mouse_z(value/10000);
11749 break;
11750
11751 case SIMULATEKEYPRESS:
11752 {
11753 //if ( !keypressed() ) break; //Don;t return values set by setting Hero->Input/Press
11754 //hmm...no, this won;t return properly for modifier keys.
11755 int32_t keyid = ri->d[rINDEX]/10000;
11756 //key = vbound(key,0,n);
11757 if (value/10000) simulate_keypress(keyid << 8);
11758 }
11759 break;
11760
11761 case KEYMODIFIERS:
11762 {
11763 key_shifts = ( value/10000 );
11764 break;
11765 }
11766 break;
11767
11768 ///----------------------------------------------------------------------------------------------------//
11769 //Itemdata Variables
11770 //not mine, but let;s guard some of them all the same -Z
11771 //item class
11772 case IDATAFAMILY:
11773 if(unsigned(ri->idata) >= MAXITEMS)
11774 {
11775 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11776 break;
11777 }
11778 (itemsbuf[ri->idata].family)=vbound(value/10000,0, 254);
11779 flushItemCache();
11780 break;
11781
11782 case IDATAUSEWPN:
11783 if(unsigned(ri->idata) >= MAXITEMS)
11784 {
11785 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11786 break;
11787 }
11788 (itemsbuf[ri->idata].useweapon)=vbound(value/10000, 0, 255);
11789 break;
11790 case IDATAUSEDEF:
11791 if(unsigned(ri->idata) >= MAXITEMS)
11792 {
11793 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11794 break;
11795 }
11796 (itemsbuf[ri->idata].usedefense)=vbound(value/10000, 0, 255);
11797 break;
11798 case IDATAWRANGE:
11799 if(unsigned(ri->idata) >= MAXITEMS)
11800 {
11801 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11802 break;
11803 }
11804 (itemsbuf[ri->idata].weaprange)=vbound(value/10000, 0, 255);
11805 break;
11806 case IDATAMAGICTIMER:
11807 if(unsigned(ri->idata) >= MAXITEMS)
11808 {
11809 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11810 break;
11811 }
11812 (itemsbuf[ri->idata].magiccosttimer[0])=vbound(value/10000, 0, 214747);
11813 break;
11814 case IDATAMAGICTIMER2:
11815 if(unsigned(ri->idata) >= MAXITEMS)
11816 {
11817 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11818 break;
11819 }
11820 (itemsbuf[ri->idata].magiccosttimer[1])=vbound(value/10000, 0, 214747);
11821 break;
11822 case IDATADURATION:
11823 if(unsigned(ri->idata) >= MAXITEMS)
11824 {
11825 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11826 break;
11827 }
11828 (itemsbuf[ri->idata].weapduration)=vbound(value/10000, 0, 255);
11829 break;
11830
11831 case IDATADUPLICATES:
11832 if(unsigned(ri->idata) >= MAXITEMS)
11833 {
11834 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11835 break;
11836 }
11837 (itemsbuf[ri->idata].duplicates)=vbound(value/10000, 0, 255);
11838 break;
11839 case IDATADRAWLAYER:
11840 if(unsigned(ri->idata) >= MAXITEMS)
11841 {
11842 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11843 break;
11844 }
11845 (itemsbuf[ri->idata].drawlayer)=vbound(value/10000, 0, 7);
11846 break;
11847 case IDATACOLLECTFLAGS:
11848 if(unsigned(ri->idata) >= MAXITEMS)
11849 {
11850 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11851 break;
11852 }
11853 //int32_t a = ri->d[rINDEX] / 10000;
11854 (itemsbuf[ri->idata].collectflags)=vbound(value/10000, 0, 214747);
11855 break;
11856 case IDATAWEAPONSCRIPT:
11857
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(unsigned(ri->idata) >= MAXITEMS)
11858 {
11859 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11860 break;
11861 }
11862 2 (itemsbuf[ri->idata].weaponscript)=vbound(value/10000, 0, 255);
11863 2 break;
11864 case IDATAWEAPHXOFS:
11865 if(unsigned(ri->idata) >= MAXITEMS)
11866 {
11867 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11868 break;
11869 }
11870 (itemsbuf[ri->idata].weap_hxofs)=(value/10000);
11871 break;
11872 case IDATAWEAPHYOFS:
11873 if(unsigned(ri->idata) >= MAXITEMS)
11874 {
11875 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11876 break;
11877 }
11878 (itemsbuf[ri->idata].weap_hyofs)=(value/10000);
11879 break;
11880 case IDATAWEAPHXSZ:
11881 if(unsigned(ri->idata) >= MAXITEMS)
11882 {
11883 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11884 break;
11885 }
11886 (itemsbuf[ri->idata].weap_hxsz)=(value/10000);
11887 break;
11888 case IDATAWEAPHYSZ:
11889 if(unsigned(ri->idata) >= MAXITEMS)
11890 {
11891 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11892 break;
11893 }
11894 (itemsbuf[ri->idata].weap_hysz)=(value/10000);
11895 break;
11896 case IDATAWEAPHZSZ:
11897 if(unsigned(ri->idata) >= MAXITEMS)
11898 {
11899 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11900 break;
11901 }
11902 (itemsbuf[ri->idata].weap_hzsz)=(value/10000);
11903 break;
11904 case IDATAWEAPXOFS:
11905 if(unsigned(ri->idata) >= MAXITEMS)
11906 {
11907 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11908 break;
11909 }
11910 (itemsbuf[ri->idata].weap_xofs)=(value/10000);
11911 break;
11912 case IDATAWEAPYOFS:
11913 if(unsigned(ri->idata) >= MAXITEMS)
11914 {
11915 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11916 break;
11917 }
11918 (itemsbuf[ri->idata].weap_yofs)=(value/10000);
11919 break;
11920
11921
11922 case IDATAHXOFS:
11923 if(unsigned(ri->idata) >= MAXITEMS)
11924 {
11925 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11926 break;
11927 }
11928 (itemsbuf[ri->idata].hxofs)=(value/10000);
11929 break;
11930 case IDATAHYOFS:
11931 if(unsigned(ri->idata) >= MAXITEMS)
11932 {
11933 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11934 break;
11935 }
11936 (itemsbuf[ri->idata].hyofs)=(value/10000);
11937 break;
11938 case IDATAHXSZ:
11939 if(unsigned(ri->idata) >= MAXITEMS)
11940 {
11941 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11942 break;
11943 }
11944 (itemsbuf[ri->idata].hxsz)=(value/10000);
11945 break;
11946 case IDATAHYSZ:
11947 if(unsigned(ri->idata) >= MAXITEMS)
11948 {
11949 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11950 break;
11951 }
11952 (itemsbuf[ri->idata].hysz)=(value/10000);
11953 break;
11954 case IDATAHZSZ:
11955 if(unsigned(ri->idata) >= MAXITEMS)
11956 {
11957 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11958 break;
11959 }
11960 (itemsbuf[ri->idata].hzsz)=(value/10000);
11961 break;
11962 case IDATADXOFS:
11963 if(unsigned(ri->idata) >= MAXITEMS)
11964 {
11965 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11966 break;
11967 }
11968 (itemsbuf[ri->idata].xofs)=(value/10000);
11969 break;
11970 case IDATADYOFS:
11971 if(unsigned(ri->idata) >= MAXITEMS)
11972 {
11973 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11974 break;
11975 }
11976 (itemsbuf[ri->idata].yofs)=(value/10000);
11977 break;
11978 case IDATATILEW:
11979 if(unsigned(ri->idata) >= MAXITEMS)
11980 {
11981 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11982 break;
11983 }
11984 (itemsbuf[ri->idata].tilew)=(value/10000);
11985 break;
11986 case IDATATILEH:
11987 if(unsigned(ri->idata) >= MAXITEMS)
11988 {
11989 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11990 break;
11991 }
11992 (itemsbuf[ri->idata].tileh)=(value/10000);
11993 break;
11994 case IDATAPICKUP:
11995 if(unsigned(ri->idata) >= MAXITEMS)
11996 {
11997 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
11998 break;
11999 }
12000 (itemsbuf[ri->idata].pickup)=(value/10000);
12001 break;
12002 case IDATAOVERRIDEFL:
12003 if(unsigned(ri->idata) >= MAXITEMS)
12004 {
12005 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12006 break;
12007 }
12008 (itemsbuf[ri->idata].overrideFLAGS)=(value/10000);
12009 break;
12010
12011 case IDATATILEWWEAP:
12012 if(unsigned(ri->idata) >= MAXITEMS)
12013 {
12014 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12015 break;
12016 }
12017 (itemsbuf[ri->idata].weap_tilew)=(value/10000);
12018 break;
12019 case IDATATILEHWEAP:
12020 if(unsigned(ri->idata) >= MAXITEMS)
12021 {
12022 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12023 break;
12024 }
12025 (itemsbuf[ri->idata].weap_tileh)=(value/10000);
12026 break;
12027 case IDATAOVERRIDEFLWEAP:
12028 if(unsigned(ri->idata) >= MAXITEMS)
12029 {
12030 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12031 break;
12032 }
12033 (itemsbuf[ri->idata].weapoverrideFLAGS)=(value/10000);
12034 break;
12035
12036 case IDATAUSEMVT:
12037 {
12038 if(unsigned(ri->idata) >= MAXITEMS)
12039 {
12040 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12041 break;
12042 }
12043 int32_t a = vbound((ri->d[rINDEX] / 10000),0,(ITEM_MOVEMENT_PATTERNS-1));
12044 (itemsbuf[ri->idata].weap_pattern[a])=vbound(value/10000, 0, 255);
12045 break;
12046 }
12047
12048 case IDATALEVEL:
12049 if(unsigned(ri->idata) >= MAXITEMS)
12050 {
12051 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12052 break;
12053 }
12054 (itemsbuf[ri->idata].fam_type)=vbound(value/10000, 0, 512);
12055 flushItemCache();
12056 break;
12057 case IDATAKEEP:
12058 item_flag(item_gamedata, value);
12059 break;
12060 case IDATAAMOUNT:
12061 {
12062 if(unsigned(ri->idata) >= MAXITEMS)
12063 {
12064 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12065 break;
12066 }
12067 int32_t v = vbound(value/10000, -9999, 16383);
12068 itemsbuf[ri->idata].amount &= 0x8000;
12069 itemsbuf[ri->idata].amount |= (abs(v)&0x3FFF)|(v<0?0x4000:0);
12070 break;
12071 }
12072 case IDATAGRADUAL:
12073 {
12074 if(unsigned(ri->idata) >= MAXITEMS)
12075 {
12076 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12077 break;
12078 }
12079 SETFLAG(itemsbuf[ri->idata].amount, 0x8000, value!=0);
12080 break;
12081 }
12082 case IDATACONSTSCRIPT:
12083 item_flag(item_passive_script, value);
12084 break;
12085 case IDATASSWIMDISABLED:
12086 item_flag(item_sideswim_disabled, value);
12087 break;
12088 case IDATABUNNYABLE:
12089 item_flag(item_bunny_enabled, value);
12090 break;
12091 case IDATAJINXIMMUNE:
12092 item_flag(item_jinx_immune, value);
12093 break;
12094 case IDATAJINXSWAP:
12095 item_flag(item_flip_jinx, value);
12096 break;
12097 case IDATAUSEBURNSPR:
12098 item_flag(item_burning_sprites, value);
12099 break;
12100 case IDATASETMAX:
12101 if(unsigned(ri->idata) >= MAXITEMS)
12102 {
12103 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12104 break;
12105 }
12106 (itemsbuf[ri->idata].setmax)=value/10000;
12107 break;
12108
12109 case IDATAMAX:
12110 if(unsigned(ri->idata) >= MAXITEMS)
12111 {
12112 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12113 break;
12114 }
12115 (itemsbuf[ri->idata].max)=value/10000;
12116 break;
12117
12118 case IDATAPOWER:
12119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 182 times.
182 if(unsigned(ri->idata) >= MAXITEMS)
12120 {
12121 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12122 break;
12123 }
12124 182 (itemsbuf[ri->idata].power)=value/10000;
12125 182 break;
12126
12127 case IDATACOUNTER:
12128 if(unsigned(ri->idata) >= MAXITEMS)
12129 {
12130 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12131 break;
12132 }
12133 (itemsbuf[ri->idata].count)=vbound(value/10000,0,31);
12134 break;
12135
12136 case IDATAPSOUND:
12137 if(unsigned(ri->idata) >= MAXITEMS)
12138 {
12139 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12140 break;
12141 }
12142 (itemsbuf[ri->idata].playsound)=vbound(value/10000, 0, 255);
12143 break;
12144
12145 case IDATAUSESOUND:
12146 if(unsigned(ri->idata) >= MAXITEMS)
12147 {
12148 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12149 break;
12150 }
12151 (itemsbuf[ri->idata].usesound)=vbound(value/10000, 0, 255);
12152 break;
12153
12154 case IDATAUSESOUND2:
12155 if(unsigned(ri->idata) >= MAXITEMS)
12156 {
12157 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12158 break;
12159 }
12160 (itemsbuf[ri->idata].usesound2)=vbound(value/10000, 0, 255);
12161 break;
12162
12163 //2.54
12164 //My additions begin here. -Z
12165 //Stack item to gain next level
12166 case IDATACOMBINE:
12167 item_flag(item_combine, value);
12168 break;
12169 //using a level of an item downgrades to a lower one
12170 case IDATADOWNGRADE:
12171 item_flag(item_downgrade, value);
12172 break;
12173 //Only validate the cost, don't charge it
12174 case IDATAVALIDATE:
12175 item_flag(item_validate_only, value);
12176 break;
12177 case IDATAVALIDATE2:
12178 item_flag(item_validate_only_2, value);
12179 break;
12180
12181
12182 //Keep Old in editor
12183 case IDATAKEEPOLD:
12184 item_flag(item_keep_old, value);
12185 break;
12186 //Ruppes for magic
12187 case IDATARUPEECOST:
12188 item_flag(item_rupee_magic, value);
12189 break;
12190 //can be eaten
12191 case IDATAEDIBLE:
12192 item_flag(item_edible, value);
12193 break;
12194 //Unused at this time
12195 case IDATAFLAGUNUSED:
12196 item_flag(item_unused, value);
12197 break;
12198 //gain lower level items
12199 case IDATAGAINLOWER:
12200 item_flag(item_gain_old, value);
12201 break;
12202 //Set the action script
12203 case IDATASCRIPT:
12204 if(unsigned(ri->idata) >= MAXITEMS)
12205 {
12206 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12207 break;
12208 }
12209 FFScript::deallocateAllScriptOwned(ScriptType::Item, ri->idata);
12210 itemsbuf[ri->idata].script=vbound(value/10000,0,255);
12211 break;
12212 case IDATASPRSCRIPT:
12213 if(unsigned(ri->idata) >= MAXITEMS)
12214 {
12215 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12216 break;
12217 }
12218 itemsbuf[ri->idata].sprite_script=vbound(value/10000,0,255);
12219 break;
12220
12221 //Hero tile modifier.
12222 case IDATALTM:
12223 {
12224 if(unsigned(ri->idata) >= MAXITEMS)
12225 {
12226 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12227 break;
12228 }
12229 auto new_value = value/10000;
12230 if (new_value != itemsbuf[ri->idata].ltm)
12231 cache_tile_mod_clear();
12232 itemsbuf[ri->idata].ltm = new_value;
12233 break;
12234 }
12235 //Pickup script
12236 case IDATAPSCRIPT:
12237 {
12238
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2760 times.
2760 if(unsigned(ri->idata) >= MAXITEMS)
12239 {
12240 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12241 break;
12242 }
12243 //Need to get collect script ref, not standard idata ref!
12244
1/2
✓ Branch 0 taken 2760 times.
✗ Branch 1 not taken.
2760 const int32_t new_ref = ri->idata!=0 ? -(ri->idata) : COLLECT_SCRIPT_ITEM_ZERO;
12245 2760 FFScript::deallocateAllScriptOwned(ScriptType::Item,new_ref);
12246 2760 itemsbuf[ri->idata].collect_script=vbound(value/10000, 0, 255);
12247 2760 break;
12248 }
12249 //pickup string
12250 case IDATAPSTRING:
12251 if(unsigned(ri->idata) >= MAXITEMS)
12252 {
12253 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12254 break;
12255 }
12256 itemsbuf[ri->idata].pstring=vbound(value/10000, 1, 255);
12257 break;
12258 case IDATAPFLAGS:
12259 if(unsigned(ri->idata) >= MAXITEMS)
12260 {
12261 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12262 break;
12263 }
12264 itemsbuf[ri->idata].pickup_string_flags=vbound(value/10000, 0, 214748);
12265 break;
12266 case IDATAPICKUPLITEMS:
12267 if(unsigned(ri->idata) >= MAXITEMS)
12268 {
12269 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12270 break;
12271 }
12272 itemsbuf[ri->idata].pickup_litems = vbound(value/10000, 0, 214748) & liALL;
12273 break;
12274 case IDATAPICKUPLITEMLEVEL:
12275 if(unsigned(ri->idata) >= MAXITEMS)
12276 {
12277 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12278 break;
12279 }
12280 itemsbuf[ri->idata].pickup_litem_level = vbound(value/10000, -1, MAXLEVELS-1);
12281 break;
12282 //magic cost
12283 case IDATAMAGCOST:
12284 if(unsigned(ri->idata) >= MAXITEMS)
12285 {
12286 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12287 break;
12288 }
12289 itemsbuf[ri->idata].cost_amount[0]=vbound(value/10000,32767,-32768);
12290 break;
12291 case IDATACOST2:
12292 if(unsigned(ri->idata) >= MAXITEMS)
12293 {
12294 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12295 break;
12296 }
12297 itemsbuf[ri->idata].cost_amount[1]=vbound(value/10000,32767,-32768);
12298 break;
12299 //cost counter ref
12300 case IDATACOSTCOUNTER:
12301 if(unsigned(ri->idata) >= MAXITEMS)
12302 {
12303 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12304 break;
12305 }
12306 itemsbuf[ri->idata].cost_counter[0]=(vbound(value/10000,-1,32));
12307 break;
12308 case IDATACOSTCOUNTER2:
12309 if(unsigned(ri->idata) >= MAXITEMS)
12310 {
12311 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12312 break;
12313 }
12314 itemsbuf[ri->idata].cost_counter[1]=(vbound(value/10000,-1,32));
12315 break;
12316 //min hearts to pick up
12317 case IDATAMINHEARTS:
12318 if(unsigned(ri->idata) >= MAXITEMS)
12319 {
12320 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12321 break;
12322 }
12323 itemsbuf[ri->idata].pickup_hearts=vbound(value/10000, 0, 214748);
12324 break;
12325 //item tile
12326 case IDATATILE:
12327
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 94 times.
94 if(unsigned(ri->idata) >= MAXITEMS)
12328 {
12329 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12330 break;
12331 }
12332 94 itemsbuf[ri->idata].tile=vbound(value/10000, 0, NEWMAXTILES-1);
12333 94 break;
12334 //flash
12335 case IDATAMISC:
12336 if(unsigned(ri->idata) >= MAXITEMS)
12337 {
12338 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12339 break;
12340 }
12341 itemsbuf[ri->idata].misc_flags=value/10000;
12342 break;
12343 //cset
12344 case IDATACSET:
12345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 if(unsigned(ri->idata) >= MAXITEMS)
12346 {
12347 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12348 break;
12349 }
12350
12351 13 itemsbuf[ri->idata].csets = (itemsbuf[ri->idata].csets & 0xF0) | vbound(value/10000,0,15);
12352
12353 // If we find quests that broke, use this code.
12354 // if (QHeader.compareVer(2, 55, 9) >= 0)
12355 // itemsbuf[ri->idata].csets = (itemsbuf[ri->idata].csets & 0xF0) | vbound(value/10000,0,15);
12356 // else
12357 // itemsbuf[ri->idata].csets = vbound(value/10000,0,13);
12358 13 break;
12359
12360 case IDATAFLASHCSET:
12361 if(unsigned(ri->idata) >= MAXITEMS)
12362 {
12363 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12364 break;
12365 }
12366
12367 itemsbuf[ri->idata].csets = (itemsbuf[ri->idata].csets & 0xF) | (vbound(value/10000,0,15)<<4);
12368 break;
12369 /*
12370 case IDATAFRAME:
12371 itemsbuf[ri->idata].frame=value/10000;
12372 break;
12373 */
12374 //A.Frames
12375 case IDATAFRAMES:
12376 if(unsigned(ri->idata) >= MAXITEMS)
12377 {
12378 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12379 break;
12380 }
12381 (itemsbuf[ri->idata].frames)=vbound(value/10000, 0, 214748);
12382 break;
12383 //A.speed
12384 case IDATAASPEED:
12385 if(unsigned(ri->idata) >= MAXITEMS)
12386 {
12387 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12388 break;
12389 }
12390 itemsbuf[ri->idata].speed=vbound(value/10000, 0, 214748);
12391 break;
12392 //Anim delay
12393 case IDATADELAY:
12394 if(unsigned(ri->idata) >= MAXITEMS)
12395 {
12396 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
12397 break;
12398 }
12399 itemsbuf[ri->idata].delay=vbound(value/10000, 0, 214748);
12400 break;
12401
12402 ///----------------------------------------------------------------------------------------------------//
12403 //LWeapon Variables
12404
12405 case LWPNSCALE:
12406 if ( get_qr(qr_OLDSPRITEDRAWS) )
12407 {
12408 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
12409 break;
12410 }
12411 if(0!=(s=checkLWpn(ri->lwpn)))
12412 ((weapon*)s)->scale=(zfix)(value/100.0);
12413
12414 break;
12415
12416 case LWPNX:
12417
2/2
✓ Branch 0 taken 6717 times.
✓ Branch 1 taken 207340 times.
214057 if(0!=(s=checkLWpn(ri->lwpn)))
12418
2/2
✓ Branch 0 taken 67473 times.
✓ Branch 1 taken 139867 times.
207340 ((weapon*)s)->x=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
12419 214057 break;
12420
12421 case SPRITEMAXLWPN:
12422 {
12423 //No bounds check, as this is a universal function and works from NULL pointers!
12424 1 Lwpns.setMax(vbound((value/10000),1,MAX_LWPN_SPRITES));
12425 1 break;
12426 }
12427
12428 case LWPNY:
12429
2/2
✓ Branch 0 taken 6717 times.
✓ Branch 1 taken 207326 times.
214043 if(0!=(s=checkLWpn(ri->lwpn)))
12430
2/2
✓ Branch 0 taken 67466 times.
✓ Branch 1 taken 139860 times.
207326 ((weapon*)s)->y=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
12431
12432 214043 break;
12433
12434 case LWPNZ:
12435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 971 times.
971 if(0!=(s=checkLWpn(ri->lwpn)))
12436 {
12437
2/2
✓ Branch 0 taken 965 times.
✓ Branch 1 taken 6 times.
971 ((weapon*)s)->z=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
12438
1/2
✓ Branch 0 taken 971 times.
✗ Branch 1 not taken.
971 if(((weapon*)s)->z < 0) ((weapon*)s)->z = 0_zf;
12439 971 }
12440
12441 971 break;
12442
12443 case LWPNJUMP:
12444
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 408 times.
408 if(0!=(s=checkLWpn(ri->lwpn)))
12445 408 ((weapon*)s)->fall=zslongToFix(value)*-100;
12446
12447 408 break;
12448
12449 case LWPNFAKEJUMP:
12450 if(0!=(s=checkLWpn(ri->lwpn)))
12451 ((weapon*)s)->fakefall=zslongToFix(value)*-100;
12452
12453 break;
12454
12455 case LWPNDIR:
12456
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71609 times.
71609 if(0!=(s=checkLWpn(ri->lwpn)))
12457 {
12458 71609 ((weapon*)s)->dir=(value/10000);
12459 71609 ((weapon*)s)->doAutoRotate(true);
12460 71609 }
12461
12462 71609 break;
12463
12464 case LWPNSPECIAL:
12465 if(0!=(s=checkLWpn(ri->lwpn)))
12466 ((weapon*)s)->specialinfo=(value/10000);
12467
12468 break;
12469
12470 case LWPNGRAVITY:
12471 if(0!=(s=checkLWpn(ri->lwpn)))
12472 {
12473 if(value)
12474 ((weapon*)s)->moveflags |= move_obeys_grav;
12475 else
12476 ((weapon*)s)->moveflags &= ~move_obeys_grav;
12477 }
12478 break;
12479
12480 case LWPNSTEP:
12481
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9786 times.
9786 if(0!=(s=checkLWpn(ri->lwpn)))
12482 {
12483 // fp math is bad for replay, so always ignore this QR when replay is active.
12484 // TODO: can we just delete this QR? Would it actually break anything? For now,
12485 // just disable for replay and wait for more tests to be played with this QR
12486 // ignored.
12487
3/4
✓ Branch 0 taken 7619 times.
✓ Branch 1 taken 2167 times.
✓ Branch 2 taken 7619 times.
✗ Branch 3 not taken.
9786 if ( get_qr(qr_STEP_IS_FLOAT) || replay_is_active() )
12488 {
12489 9786 ((weapon*)s)->step= zslongToFix(value / 100);
12490 9786 }
12491 else
12492 {
12493 //old, buggy code replication, round two: Go! -Z
12494 //zfix val = zslongToFix(value);
12495 //val.doFloor();
12496 //((weapon*)s)->step = ((val / 100.0).getFloat());
12497
12498 //old, buggy code replication, round THREE: Go! -Z
12499 ((weapon*)s)->step = ((value/10000)/100.0);
12500 }
12501
12502 9786 }
12503
12504 9786 break;
12505
12506 case LWPNANGLE:
12507
1/2
✓ Branch 0 taken 1679 times.
✗ Branch 1 not taken.
1679 if(0!=(s=checkLWpn(ri->lwpn)))
12508 {
12509 1679 ((weapon*)s)->angle=(double)(value/10000.0);
12510 1679 ((weapon*)(s))->doAutoRotate();
12511 1679 }
12512
12513 1679 break;
12514
12515 case LWPNDEGANGLE:
12516 if(0!=(s=checkLWpn(ri->lwpn)))
12517 {
12518 double rangle = (value / 10000.0) * (PI / 180.0);
12519 ((weapon*)s)->angle=(double)(rangle);
12520 ((weapon*)(s))->doAutoRotate();
12521 }
12522
12523 break;
12524
12525 case LWPNVX:
12526
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
12527 {
12528 double vy;
12529 6 double vx = (value / 10000.0);
12530
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (((weapon*)(s))->angular)
12531 vy = zc::math::Sin(((weapon*)s)->angle)*((weapon*)s)->step;
12532 else
12533 {
12534
5/7
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 2 times.
6 switch(NORMAL_DIR(((weapon*)(s))->dir))
12535 {
12536 case l_up:
12537 case r_up:
12538 case up:
12539 2 vy = -1.0*((weapon*)s)->step;
12540 2 break;
12541 case l_down:
12542 case r_down:
12543 case down:
12544 2 vy = ((weapon*)s)->step;
12545 2 break;
12546
12547 default:
12548 2 vy = 0;
12549 2 break;
12550 }
12551 }
12552 6 ((weapon*)s)->angular = true;
12553 6 ((weapon*)s)->angle=atan2(vy, vx);
12554 6 ((weapon*)s)->step=FFCore.Distance(0, 0, vx, vy)/10000.0;
12555 6 ((weapon*)(s))->doAutoRotate();
12556 6 }
12557
12558 6 break;
12559
12560 case LWPNVY:
12561
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
12562 {
12563 double vx;
12564 6 double vy = (value / 10000.0);
12565
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (((weapon*)(s))->angular)
12566 6 vx = zc::math::Cos(((weapon*)s)->angle)*((weapon*)s)->step;
12567 else
12568 {
12569 switch(NORMAL_DIR(((weapon*)(s))->dir))
12570 {
12571 case l_up:
12572 case l_down:
12573 case left:
12574 vx = -1.0*((weapon*)s)->step;
12575 break;
12576 case r_down:
12577 case r_up:
12578 case right:
12579 vx = ((weapon*)s)->step;
12580 break;
12581
12582 default:
12583 vx = 0;
12584 break;
12585 }
12586 }
12587 6 ((weapon*)s)->angular = true;
12588 6 ((weapon*)s)->angle=atan2(vy, vx);
12589 6 ((weapon*)s)->step=FFCore.Distance(0, 0, vx, vy)/10000.0;
12590 6 ((weapon*)(s))->doAutoRotate();
12591 6 }
12592
12593 6 break;
12594
12595 case LWPNANGULAR:
12596
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1181 times.
1181 if(0!=(s=checkLWpn(ri->lwpn)))
12597 {
12598 1181 ((weapon*)s)->angular=(value!=0);
12599 1181 ((weapon*)(s))->doAutoRotate(false, true);
12600 1181 }
12601
12602 1181 break;
12603
12604 case LWPNAUTOROTATE:
12605 if(0!=(s=checkLWpn(ri->lwpn)))
12606 {
12607 ((weapon*)s)->autorotate=(value!=0);
12608 ((weapon*)(s))->doAutoRotate(false, true);
12609 }
12610
12611 break;
12612
12613 case LWPNBEHIND:
12614
1/2
✓ Branch 0 taken 1131 times.
✗ Branch 1 not taken.
1131 if(0!=(s=checkLWpn(ri->lwpn)))
12615 1131 ((weapon*)s)->behind=(value!=0);
12616
12617 1131 break;
12618
12619 case LWPNDRAWTYPE:
12620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 476 times.
476 if(0!=(s=checkLWpn(ri->lwpn)))
12621 476 ((weapon*)s)->drawstyle=(value/10000);
12622
12623 476 break;
12624
12625 case LWPNPOWER:
12626
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76041 times.
76041 if(0!=(s=checkLWpn(ri->lwpn)))
12627 76041 ((weapon*)s)->power=(value/10000);
12628
12629 76041 break;
12630 /*
12631 case LWPNRANGE:
12632 if(0!=(s=checkLWpn(ri->lwpn)))
12633 ((weapon*)s)->scriptrange=vbound((value/10000),0,512); //Allow it to move off-screen. -Z
12634 break;
12635 */
12636 case LWPNDEAD:
12637
2/2
✓ Branch 0 taken 6717 times.
✓ Branch 1 taken 147078 times.
153795 if(0!=(s=checkLWpn(ri->lwpn)))
12638 {
12639 147078 auto dead = value/10000;
12640 147078 ((weapon*)s)->dead=dead;
12641
2/2
✓ Branch 0 taken 74907 times.
✓ Branch 1 taken 72171 times.
147078 if(dead != 0) ((weapon*)s)->weapon_dying_frame = false;
12642 147078 }
12643 153795 break;
12644
12645 case LWPNID:
12646 if(0!=(s=checkLWpn(ri->lwpn)))
12647 ((weapon*)s)->id=(value/10000);
12648
12649 break;
12650
12651 case LWPNTILE:
12652
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2464 times.
2464 if(0!=(s=checkLWpn(ri->lwpn)))
12653 2464 ((weapon*)s)->tile=(value/10000);
12654
12655 2464 break;
12656
12657 case LWPNSCRIPTTILE:
12658
1/2
✓ Branch 0 taken 3263 times.
✗ Branch 1 not taken.
3263 if(0!=(s=checkLWpn(ri->lwpn)))
12659 3263 ((weapon*)s)->scripttile=vbound((value/10000),-1,NEWMAXTILES-1);
12660
12661 3263 break;
12662
12663 case LWPNSCRIPTFLIP:
12664 if(0!=(s=checkLWpn(ri->lwpn)))
12665 ((weapon*)s)->scriptflip=vbound((value/10000),-1,127);
12666
12667 break;
12668
12669 case LWPNCSET:
12670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26540 times.
26540 if(0!=(s=checkLWpn(ri->lwpn)))
12671 26540 ((weapon*)s)->cs=(value/10000)&15;
12672
12673 26540 break;
12674
12675 case LWPNFLASHCSET:
12676
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(0!=(s=checkLWpn(ri->lwpn)))
12677 6 (((weapon*)s)->o_cset)|=(value/10000)<<4;
12678
12679 6 break;
12680
12681 case LWPNFRAMES:
12682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 429 times.
429 if(0!=(s=checkLWpn(ri->lwpn)))
12683 429 ((weapon*)s)->frames=(value/10000);
12684
12685 429 break;
12686
12687 case LWPNFRAME:
12688
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
12689 6 ((weapon*)s)->aframe=(value/10000);
12690
12691 6 break;
12692
12693 case LWPNASPEED:
12694
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 527 times.
527 if(0!=(s=checkLWpn(ri->lwpn)))
12695 527 ((weapon*)s)->o_speed=(value/10000);
12696
12697 527 break;
12698
12699 case LWPNFLASH:
12700
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
12701 6 ((weapon*)s)->flash=(value/10000);
12702
12703 6 break;
12704
12705 case LWPNFLIP:
12706
1/2
✓ Branch 0 taken 885 times.
✗ Branch 1 not taken.
885 if(0!=(s=checkLWpn(ri->lwpn)))
12707 885 ((weapon*)s)->flip=(value/10000);
12708
12709 885 break;
12710
12711 case LWPNROTATION:
12712
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4922 times.
4922 if ( get_qr(qr_OLDSPRITEDRAWS) )
12713 {
12714 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
12715 break;
12716 }
12717
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4922 times.
4922 if(0!=(s=checkLWpn(ri->lwpn)))
12718 4922 ((weapon*)s)->rotation=(value/10000);
12719
12720 4922 break;
12721
12722 case LWPNEXTEND:
12723
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 839 times.
839 if(0!=(s=checkLWpn(ri->lwpn)))
12724 839 ((weapon*)s)->extend=(value/10000);
12725
12726 839 break;
12727
12728 case LWPNOTILE:
12729
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2345 times.
2345 if(0!=(s=checkLWpn(ri->lwpn)))
12730 {
12731 2345 ((weapon*)s)->o_tile=(value/10000);
12732 2345 ((weapon*)s)->ref_o_tile=(value/10000);
12733 //((weapon*)s)->script_wrote_otile=1; //Removing this as of 26th October, 2019 -Z
12734 //if at some future point we WANT writing ->Tile to also overwrite ->OriginalTile,
12735 //then either the user will need to manually write tile, or we can add a QR and
12736 // write ->tile here. 'script_wrote_otile' is out.
12737 2345 }
12738 2345 break;
12739
12740 case LWPNOCSET:
12741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
12742 6 (((weapon*)s)->o_cset)|=(value/10000)&15;
12743
12744 6 break;
12745
12746 case LWPNHXOFS:
12747
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71310 times.
71310 if(0!=(s=checkLWpn(ri->lwpn)))
12748 71310 (((weapon*)s)->hxofs)=(value/10000);
12749
12750 71310 break;
12751
12752 case LWPNHYOFS:
12753
1/2
✓ Branch 0 taken 71308 times.
✗ Branch 1 not taken.
71308 if(0!=(s=checkLWpn(ri->lwpn)))
12754 71308 (((weapon*)s)->hyofs)=(value/10000);
12755
12756 71308 break;
12757
12758 case LWPNXOFS:
12759
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1768 times.
1768 if(0!=(s=checkLWpn(ri->lwpn)))
12760 1768 (((weapon*)s)->xofs)=(zfix)(value/10000);
12761
12762 1768 break;
12763
12764 case LWPNYOFS:
12765
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70954 times.
70954 if(0!=(s=checkLWpn(ri->lwpn)))
12766
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70954 times.
70954 (((weapon*)s)->yofs)=(zfix)(value/10000)+(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset);
12767
12768 70954 break;
12769
12770 case LWPNSHADOWXOFS:
12771 if(0!=(s=checkLWpn(ri->lwpn)))
12772 (((weapon*)s)->shadowxofs)=(zfix)(value/10000);
12773
12774 break;
12775
12776 case LWPNSHADOWYOFS:
12777 if(0!=(s=checkLWpn(ri->lwpn)))
12778 (((weapon*)s)->shadowyofs)=(zfix)(value/10000);
12779
12780 break;
12781
12782 case LWPNTOTALDYOFFS:
12783 break; //READ-ONLY
12784
12785 case LWPNZOFS:
12786
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
12787 6 (((weapon*)s)->zofs)=(zfix)(value/10000);
12788
12789 6 break;
12790
12791 case LWPNHXSZ:
12792
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72525 times.
72525 if(0!=(s=checkLWpn(ri->lwpn)))
12793 72525 (((weapon*)s)->hit_width)=(value/10000);
12794
12795 72525 break;
12796
12797 case LWPNHYSZ:
12798
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72542 times.
72542 if(0!=(s=checkLWpn(ri->lwpn)))
12799 72542 (((weapon*)s)->hit_height)=(value/10000);
12800
12801 72542 break;
12802
12803 case LWPNHZSZ:
12804
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(0!=(s=checkLWpn(ri->lwpn)))
12805 6 (((weapon*)s)->hzsz)=(value/10000);
12806
12807 6 break;
12808
12809 case LWPNTXSZ:
12810
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 833 times.
833 if(0!=(s=checkLWpn(ri->lwpn)))
12811 833 (((weapon*)s)->txsz)=vbound((value/10000),1,20);
12812
12813 833 break;
12814
12815 case LWPNTYSZ:
12816
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 833 times.
833 if(0!=(s=checkLWpn(ri->lwpn)))
12817 833 (((weapon*)s)->tysz)=vbound((value/10000),1,20);
12818
12819 833 break;
12820
12821 case LWPNCOLLDET:
12822
1/2
✓ Branch 0 taken 18928 times.
✗ Branch 1 not taken.
18928 if(0!=(s=checkLWpn(ri->lwpn)))
12823 18928 (((weapon*)(s))->scriptcoldet) = value;
12824
12825 18928 break;
12826
12827 case LWPNENGINEANIMATE:
12828 if(0!=(s=checkLWpn(ri->lwpn)))
12829 (((weapon*)(s))->do_animation)=value;
12830
12831 break;
12832
12833 case LWPNPARENT:
12834 {
12835 //int32_t pitm = (vbound(value/10000,1,(MAXITEMS-1)));
12836
12837
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
42 if(0!=(s=checkLWpn(ri->lwpn)))
12838 42 (((weapon*)(s))->parentitem)=(vbound(value/10000,-1,(MAXITEMS-1)));
12839 42 break;
12840 }
12841
12842 case LWPNLEVEL:
12843
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(0!=(s=checkLWpn(ri->lwpn)))
12844 12 (((weapon*)(s))->type)=value/10000;
12845
12846 12 break;
12847
12848 case LWPNSCRIPT:
12849
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62002 times.
62002 if(0!=(s=checkLWpn(ri->lwpn)))
12850 {
12851 62002 (((weapon*)(s))->weaponscript)=vbound(value/10000,0,NUMSCRIPTWEAPONS-1);
12852
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62002 times.
62002 if ( get_qr(qr_CLEARINITDONSCRIPTCHANGE))
12853 {
12854
2/2
✓ Branch 0 taken 496016 times.
✓ Branch 1 taken 62002 times.
558018 for(int32_t q=0; q<8; q++)
12855 496016 (((weapon*)(s))->weap_initd[q]) = 0;
12856 62002 }
12857 62002 on_reassign_script_engine_data(ScriptType::Lwpn, ri->lwpn);
12858 62002 }
12859 62002 break;
12860
12861 case LWPNUSEWEAPON:
12862
1/2
✓ Branch 0 taken 1130 times.
✗ Branch 1 not taken.
1130 if(0!=(s=checkLWpn(ri->lwpn)))
12863 1130 (((weapon*)(s))->useweapon)=vbound(value/10000,0,255);
12864
12865 1130 break;
12866
12867 case LWPNUSEDEFENCE:
12868 if(0!=(s=checkLWpn(ri->lwpn)))
12869 (((weapon*)(s))->usedefense)=vbound(value/10000,0,255);
12870
12871 break;
12872
12873 case LWPNFALLCLK:
12874 if(0!=(s=checkLWpn(ri->lwpn)))
12875 {
12876 if(((weapon*)(s))->fallclk != 0 && value == 0)
12877 {
12878 ((weapon*)(s))->cs = ((weapon*)(s))->o_cset;
12879 ((weapon*)(s))->tile = ((weapon*)(s))->o_tile;
12880 }
12881 else if(((weapon*)(s))->fallclk == 0 && value != 0) ((weapon*)(s))->o_cset = ((weapon*)(s))->cs;
12882 ((weapon*)(s))->fallclk = vbound(value/10000,0,70);
12883 }
12884 break;
12885 case LWPNFALLCMB:
12886 if(0!=(s=checkLWpn(ri->lwpn)))
12887 {
12888 ((weapon*)(s))->fallCombo = vbound(value/10000,0,MAXCOMBOS-1);
12889 }
12890 break;
12891 case LWPNDROWNCLK:
12892 if(0!=(s=checkLWpn(ri->lwpn)))
12893 {
12894 if(((weapon*)(s))->drownclk != 0 && value == 0)
12895 {
12896 ((weapon*)(s))->cs = ((weapon*)(s))->o_cset;
12897 ((weapon*)(s))->tile = ((weapon*)(s))->o_tile;
12898 }
12899 else if(((weapon*)(s))->drownclk == 0 && value != 0) ((weapon*)(s))->o_cset = ((weapon*)(s))->cs;
12900 ((weapon*)(s))->drownclk = vbound(value/10000,0,70);
12901 }
12902 break;
12903 case LWPNDROWNCMB:
12904 if(0!=(s=checkLWpn(ri->lwpn)))
12905 {
12906 ((weapon*)(s))->drownCombo = vbound(value/10000,0,MAXCOMBOS-1);
12907 }
12908 break;
12909 case LWPNFAKEZ:
12910 if(0!=(s=checkLWpn(ri->lwpn)))
12911 {
12912 ((weapon*)s)->fakez=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
12913 if(((weapon*)s)->fakez < 0) ((weapon*)s)->fakez = 0_zf;
12914 }
12915
12916 break;
12917
12918 case LWPNGLOWRAD:
12919
1/2
✓ Branch 0 taken 527 times.
✗ Branch 1 not taken.
527 if(0!=(s=checkLWpn(ri->lwpn)))
12920 {
12921 527 ((weapon*)(s))->glowRad = vbound(value/10000,0,255);
12922 527 }
12923 527 break;
12924
12925 case LWPNGLOWSHP:
12926 if(0!=(s=checkLWpn(ri->lwpn)))
12927 {
12928 ((weapon*)(s))->glowShape = vbound(value/10000,0,255);
12929 }
12930 break;
12931
12932 case LWPNUNBL:
12933 if(0!=(s=checkLWpn(ri->lwpn)))
12934 {
12935 ((weapon*)(s))->unblockable = (value/10000)&WPNUNB_ALL;
12936 }
12937 break;
12938
12939 case LWPNSHADOWSPR:
12940 if(0!=(s=checkLWpn(ri->lwpn)))
12941 {
12942 ((weapon*)(s))->spr_shadow = vbound(value/10000, 0, 255);
12943 }
12944 break;
12945 case LWSWHOOKED:
12946 break; //read-only
12947 case LWPNTIMEOUT:
12948 if(0!=(s=checkLWpn(ri->lwpn)))
12949 {
12950 ((weapon*)(s))->weap_timeout = vbound(value/10000,0,214748);
12951 }
12952 break;
12953 case LWPNDEATHITEM:
12954 if(0!=(s=checkLWpn(ri->lwpn)))
12955 {
12956 ((weapon*)(s))->death_spawnitem = vbound(value/10000,-1,MAXITEMS-1);
12957 }
12958 break;
12959 case LWPNDEATHDROPSET:
12960 if(0!=(s=checkLWpn(ri->lwpn)))
12961 {
12962 ((weapon*)(s))->death_spawndropset = vbound(value/10000,-1,MAXITEMDROPSETS-1);
12963 }
12964 break;
12965 case LWPNDEATHIPICKUP:
12966 if(0!=(s=checkLWpn(ri->lwpn)))
12967 {
12968 ((weapon*)(s))->death_item_pflags = value/10000;
12969 }
12970 break;
12971 case LWPNDEATHSPRITE:
12972 if(0!=(s=checkLWpn(ri->lwpn)))
12973 {
12974 ((weapon*)(s))->death_sprite = vbound(value/10000,-255,MAXWPNS-1);
12975 }
12976 break;
12977 case LWPNDEATHSFX:
12978 if(0!=(s=checkLWpn(ri->lwpn)))
12979 {
12980 ((weapon*)(s))->death_sfx = vbound(value/10000,0,WAV_COUNT);
12981 }
12982 break;
12983 case LWPNLIFTLEVEL:
12984 if(0!=(s=checkLWpn(ri->lwpn)))
12985 {
12986 ((weapon*)(s))->lift_level = vbound(value/10000,0,255);
12987 }
12988 break;
12989 case LWPNLIFTTIME:
12990 if(0!=(s=checkLWpn(ri->lwpn)))
12991 {
12992 ((weapon*)(s))->lift_time = vbound(value/10000,0,255);
12993 }
12994 break;
12995 case LWPNLIFTHEIGHT:
12996 if(0!=(s=checkLWpn(ri->lwpn)))
12997 {
12998 ((weapon*)(s))->lift_height = zslongToFix(value);
12999 }
13000 break;
13001
13002 ///----------------------------------------------------------------------------------------------------//
13003 //EWeapon Variables
13004 case EWPNSCALE:
13005 if ( get_qr(qr_OLDSPRITEDRAWS) )
13006 {
13007 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'.");
13008 break;
13009 }
13010 if(0!=(s=checkEWpn(ri->ewpn)))
13011 ((weapon*)s)->scale=(zfix)(value/100.0);
13012
13013 break;
13014
13015 case EWPNX:
13016
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 390183 times.
390183 if(0!=(s=checkEWpn(ri->ewpn)))
13017
2/2
✓ Branch 0 taken 38744 times.
✓ Branch 1 taken 351439 times.
390183 ((weapon*)s)->x = (get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000));
13018
13019 390183 break;
13020
13021 case SPRITEMAXEWPN:
13022 {
13023 //No bounds check, as this is a universal function and works from NULL pointers!
13024 1 Ewpns.setMax(vbound((value/10000),1,MAX_EWPN_SPRITES));
13025 1 break;
13026 }
13027
13028 case EWPNY:
13029
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 390780 times.
390780 if(0!=(s=checkEWpn(ri->ewpn)))
13030
2/2
✓ Branch 0 taken 38610 times.
✓ Branch 1 taken 352170 times.
390780 ((weapon*)s)->y = (get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000));
13031
13032 390780 break;
13033
13034 case EWPNZ:
13035
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57530 times.
57530 if(0!=(s=checkEWpn(ri->ewpn)))
13036 {
13037
2/2
✓ Branch 0 taken 1291 times.
✓ Branch 1 taken 56239 times.
57530 ((weapon*)s)->z=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
13038
2/2
✓ Branch 0 taken 57119 times.
✓ Branch 1 taken 411 times.
57530 if(((weapon*)s)->z < 0) ((weapon*)s)->z = 0_zf;
13039 57530 }
13040
13041 57530 break;
13042
13043 case EWPNJUMP:
13044
1/2
✓ Branch 0 taken 55587 times.
✗ Branch 1 not taken.
55587 if(0!=(s=checkEWpn(ri->ewpn)))
13045 55587 ((weapon*)s)->fall=zslongToFix(value)*-100;
13046
13047 55587 break;
13048
13049 case EWPNFAKEJUMP:
13050 if(0!=(s=checkEWpn(ri->ewpn)))
13051 ((weapon*)s)->fakefall=zslongToFix(value)*-100;
13052
13053 break;
13054
13055 case EWPNDIR:
13056
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 227256 times.
227256 if(0!=(s=checkEWpn(ri->ewpn)))
13057 {
13058 227256 ((weapon*)s)->dir=(value/10000);
13059 227256 ((weapon*)s)->doAutoRotate(true);
13060 227256 }
13061
13062 227256 break;
13063
13064 case EWPNLEVEL:
13065
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
117 if(0!=(s=checkEWpn(ri->ewpn)))
13066 117 ((weapon*)s)->type=(value/10000);
13067
13068 117 break;
13069
13070 case EWPNGRAVITY:
13071 if(0!=(s=checkEWpn(ri->ewpn)))
13072 {
13073 if(value)
13074 ((weapon*)s)->moveflags |= move_obeys_grav;
13075 else
13076 ((weapon*)s)->moveflags &= ~move_obeys_grav;
13077 }
13078 break;
13079
13080 case EWPNSTEP:
13081
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 372485 times.
372485 if(0!=(s=checkEWpn(ri->ewpn)))
13082 {
13083
3/4
✓ Branch 0 taken 350322 times.
✓ Branch 1 taken 22163 times.
✓ Branch 2 taken 350322 times.
✗ Branch 3 not taken.
372485 if ( get_qr(qr_STEP_IS_FLOAT) || replay_is_active() )
13084 {
13085 372485 ((weapon*)s)->step= zslongToFix(value / 100);
13086 372485 }
13087 else
13088 {
13089 //old, buggy code replication, round two: Go! -Z
13090 //zfix val = zslongToFix(value);
13091 //val.doFloor();
13092 //((weapon*)s)->step = ((val / 100.0).getFloat());
13093
13094 //old, buggy code replication, round THREE: Go! -Z
13095 ((weapon*)s)->step = ((value/10000)/100.0);
13096 }
13097 372485 }
13098
13099 372485 break;
13100
13101 case EWPNANGLE:
13102
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 220884 times.
220890 if(0!=(s=checkEWpn(ri->ewpn)))
13103 {
13104 220884 ((weapon*)s)->angle=(double)(value/10000.0);
13105 220884 ((weapon*)(s))->doAutoRotate();
13106 220884 }
13107
13108 220890 break;
13109
13110 case EWPNDEGANGLE:
13111 if(0!=(s=checkEWpn(ri->ewpn)))
13112 {
13113 double rangle = (value / 10000.0) * (PI / 180.0);
13114 ((weapon*)s)->angle=(double)(rangle);
13115 ((weapon*)(s))->doAutoRotate();
13116 }
13117
13118 break;
13119
13120 case EWPNVX:
13121 if(0!=(s=checkEWpn(ri->ewpn)))
13122 {
13123 double vy;
13124 double vx = (value / 10000.0);
13125 if (((weapon*)(s))->angular)
13126 vy = zc::math::Sin(((weapon*)s)->angle)*((weapon*)s)->step;
13127 else
13128 {
13129 switch(NORMAL_DIR(((weapon*)(s))->dir))
13130 {
13131 case l_up:
13132 case r_up:
13133 case up:
13134 vy = -1.0*((weapon*)s)->step;
13135 break;
13136 case l_down:
13137 case r_down:
13138 case down:
13139 vy = ((weapon*)s)->step;
13140 break;
13141
13142 default:
13143 vy = 0;
13144 break;
13145 }
13146 }
13147 ((weapon*)s)->angular = true;
13148 ((weapon*)s)->angle=atan2(vy, vx);
13149 ((weapon*)s)->step=FFCore.Distance(0, 0, vx, vy)/10000;
13150 ((weapon*)(s))->doAutoRotate();
13151 }
13152
13153 break;
13154
13155 case EWPNVY:
13156 if(0!=(s=checkEWpn(ri->ewpn)))
13157 {
13158 double vx;
13159 double vy = (value / 10000.0);
13160 if (((weapon*)(s))->angular)
13161 vx = zc::math::Cos(((weapon*)s)->angle)*((weapon*)s)->step;
13162 else
13163 {
13164 switch(NORMAL_DIR(((weapon*)(s))->dir))
13165 {
13166 case l_up:
13167 case l_down:
13168 case left:
13169 vx = -1.0*((weapon*)s)->step;
13170 break;
13171 case r_down:
13172 case r_up:
13173 case right:
13174 vx = ((weapon*)s)->step;
13175 break;
13176
13177 default:
13178 vx = 0;
13179 break;
13180 }
13181 }
13182 ((weapon*)s)->angular = true;
13183 ((weapon*)s)->angle=atan2(vy, vx);
13184 ((weapon*)s)->step=FFCore.Distance(0, 0, vx, vy)/10000;
13185 ((weapon*)(s))->doAutoRotate();
13186 }
13187
13188 break;
13189
13190 case EWPNANGULAR:
13191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 208988 times.
208988 if(0!=(s=checkEWpn(ri->ewpn)))
13192 {
13193 208988 ((weapon*)s)->angular=(value!=0);
13194 208988 ((weapon*)(s))->doAutoRotate(false, true);
13195 208988 }
13196
13197 208988 break;
13198
13199 case EWPNAUTOROTATE:
13200 if(0!=(s=checkEWpn(ri->ewpn)))
13201 {
13202 ((weapon*)s)->autorotate=(value!=0);
13203 ((weapon*)(s))->doAutoRotate(false, true);
13204 }
13205
13206 break;
13207
13208 case EWPNBEHIND:
13209
1/2
✓ Branch 0 taken 5420 times.
✗ Branch 1 not taken.
5420 if(0!=(s=checkEWpn(ri->ewpn)))
13210 5420 ((weapon*)s)->behind=(value!=0);
13211
13212 5420 break;
13213
13214 case EWPNDRAWTYPE:
13215
1/2
✓ Branch 0 taken 12175 times.
✗ Branch 1 not taken.
12175 if(0!=(s=checkEWpn(ri->ewpn)))
13216 12175 ((weapon*)s)->drawstyle=(value/10000);
13217
13218 12175 break;
13219
13220 case EWPNPOWER:
13221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 210232 times.
210232 if(0!=(s=checkEWpn(ri->ewpn)))
13222 210232 ((weapon*)s)->power=(value/10000);
13223
13224 210232 break;
13225
13226 case EWPNDEAD:
13227
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 114186 times.
114186 if(0!=(s=checkEWpn(ri->ewpn)))
13228 {
13229 114186 auto dead = value/10000;
13230 114186 ((weapon*)s)->dead=dead;
13231
2/2
✓ Branch 0 taken 86149 times.
✓ Branch 1 taken 28037 times.
114186 if(dead != 0) ((weapon*)s)->weapon_dying_frame = false;
13232 114186 }
13233
13234 114186 break;
13235
13236 case EWPNID:
13237 if(0!=(s=checkEWpn(ri->ewpn)))
13238 ((weapon*)s)->id=(value/10000);
13239
13240 break;
13241
13242 case EWPNTILE:
13243
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 74446 times.
74446 if(0!=(s=checkEWpn(ri->ewpn)))
13244 74446 ((weapon*)s)->tile=(value/10000);
13245
13246 74446 break;
13247
13248 case EWPNSCRIPTTILE:
13249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 178 times.
178 if(0!=(s=checkEWpn(ri->ewpn)))
13250 178 ((weapon*)s)->scripttile=vbound((value/10000),-1, NEWMAXTILES-1);
13251
13252 178 break;
13253
13254 case EWPNSCRIPTFLIP:
13255 if(0!=(s=checkEWpn(ri->ewpn)))
13256 ((weapon*)s)->scriptflip=vbound((value/10000),-1, 127);
13257
13258 break;
13259
13260 case EWPNCSET:
13261
1/2
✓ Branch 0 taken 35337 times.
✗ Branch 1 not taken.
35337 if(0!=(s=checkEWpn(ri->ewpn)))
13262 35337 ((weapon*)s)->cs=(value/10000)&15;
13263
13264 35337 break;
13265
13266 case EWPNFLASHCSET:
13267 if(0!=(s=checkEWpn(ri->ewpn)))
13268 (((weapon*)s)->o_cset)|=(value/10000)<<4;
13269
13270 break;
13271
13272 case EWPNFRAMES:
13273
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if(0!=(s=checkEWpn(ri->ewpn)))
13274 41 ((weapon*)s)->frames=(value/10000);
13275
13276 41 break;
13277
13278 case EWPNFRAME:
13279
1/2
✓ Branch 0 taken 1039 times.
✗ Branch 1 not taken.
1039 if(0!=(s=checkEWpn(ri->ewpn)))
13280 1039 ((weapon*)s)->aframe=(value/10000);
13281
13282 1039 break;
13283
13284 case EWPNASPEED:
13285
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if(0!=(s=checkEWpn(ri->ewpn)))
13286 41 ((weapon*)s)->o_speed=(value/10000);
13287
13288 41 break;
13289
13290 case EWPNFLASH:
13291
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 549 times.
549 if(0!=(s=checkEWpn(ri->ewpn)))
13292 549 ((weapon*)s)->flash=(value/10000);
13293
13294 549 break;
13295
13296 case EWPNFLIP:
13297
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 78832 times.
78832 if(0!=(s=checkEWpn(ri->ewpn)))
13298 78832 ((weapon*)s)->flip=(value/10000);
13299
13300 78832 break;
13301
13302 case EWPNROTATION:
13303
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1104 times.
1104 if ( get_qr(qr_OLDSPRITEDRAWS) )
13304 {
13305 scripting_log_error_with_context("To use this you must disable the quest rule 'Old (Faster) Sprite Drawing'");
13306 break;
13307 }
13308
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1104 times.
1104 if(0!=(s=checkEWpn(ri->ewpn)))
13309 1104 ((weapon*)s)->rotation=(value/10000);
13310
13311 1104 break;
13312
13313 case EWPNEXTEND:
13314
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 156969 times.
156969 if(0!=(s=checkEWpn(ri->ewpn)))
13315 156969 ((weapon*)s)->extend=(value/10000);
13316
13317 156969 break;
13318
13319 case EWPNOTILE:
13320
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4552 times.
4552 if(0!=(s=checkEWpn(ri->ewpn)))
13321 {
13322 4552 ((weapon*)s)->o_tile=(value/10000);
13323 4552 ((weapon*)s)->ref_o_tile=(value/10000);
13324 4552 }
13325
13326 4552 break;
13327
13328 case EWPNOCSET:
13329 if(0!=(s=checkEWpn(ri->ewpn)))
13330 (((weapon*)s)->o_cset)|=(value/10000)&15;
13331
13332 break;
13333
13334 case EWPNHXOFS:
13335
1/2
✓ Branch 0 taken 194229 times.
✗ Branch 1 not taken.
194229 if(0!=(s=checkEWpn(ri->ewpn)))
13336 194229 (((weapon*)s)->hxofs)=(value/10000);
13337
13338 194229 break;
13339
13340 case EWPNHYOFS:
13341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 193736 times.
193736 if(0!=(s=checkEWpn(ri->ewpn)))
13342 193736 (((weapon*)s)->hyofs)=(value/10000);
13343
13344 193736 break;
13345
13346 case EWPNXOFS:
13347
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 84990 times.
84994 if(0!=(s=checkEWpn(ri->ewpn)))
13348 84990 (((weapon*)s)->xofs)=(zfix)(value/10000);
13349
13350 84994 break;
13351
13352 case EWPNYOFS:
13353
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44193 times.
44193 if(0!=(s=checkEWpn(ri->ewpn)))
13354
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44193 times.
44193 (((weapon*)s)->yofs)=(zfix)(value/10000)+(get_qr(qr_OLD_DRAWOFFSET)?playing_field_offset:original_playing_field_offset);
13355
13356 44193 break;
13357
13358 case EWPNSHADOWXOFS:
13359 if(0!=(s=checkEWpn(ri->ewpn)))
13360 (((weapon*)s)->shadowxofs)=(zfix)(value/10000);
13361
13362 break;
13363
13364 case EWPNSHADOWYOFS:
13365 if(0!=(s=checkEWpn(ri->ewpn)))
13366 (((weapon*)s)->shadowyofs)=(zfix)(value/10000);
13367
13368 break;
13369
13370 case EWPNZOFS:
13371 if(0!=(s=checkEWpn(ri->ewpn)))
13372 (((weapon*)s)->zofs)=(zfix)(value/10000);
13373
13374 break;
13375
13376 case EWPNHXSZ:
13377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 325611 times.
325611 if(0!=(s=checkEWpn(ri->ewpn)))
13378 325611 (((weapon*)s)->hit_width)=(value/10000);
13379
13380 325611 break;
13381
13382 case EWPNHYSZ:
13383
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 325024 times.
325024 if(0!=(s=checkEWpn(ri->ewpn)))
13384 325024 (((weapon*)s)->hit_height)=(value/10000);
13385
13386 325024 break;
13387
13388 case EWPNHZSZ:
13389
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
44 if(0!=(s=checkEWpn(ri->ewpn)))
13390 44 (((weapon*)s)->hzsz)=(value/10000);
13391
13392 44 break;
13393
13394 case EWPNTXSZ:
13395
1/2
✓ Branch 0 taken 202345 times.
✗ Branch 1 not taken.
202345 if(0!=(s=checkEWpn(ri->ewpn)))
13396 202345 (((weapon*)s)->txsz)=vbound((value/10000),1,20);
13397
13398 202345 break;
13399
13400 case EWPNTYSZ:
13401
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 202345 times.
202345 if(0!=(s=checkEWpn(ri->ewpn)))
13402 202345 (((weapon*)s)->tysz)=vbound((value/10000),1,20);
13403
13404 202345 break;
13405
13406 case EWPNCOLLDET:
13407
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31616 times.
31616 if(0!=(s=checkEWpn(ri->ewpn)))
13408 31616 (((weapon*)(s))->scriptcoldet)=value;
13409
13410 31616 break;
13411
13412 case EWPNENGINEANIMATE:
13413 if(0!=(s=checkEWpn(ri->ewpn)))
13414 (((weapon*)(s))->do_animation)=value;
13415
13416 break;
13417
13418
13419 case EWPNPARENTUID:
13420 if(0!=(s=checkEWpn(ri->ewpn)))
13421 s->setParent(sprite::getByUID(value));
13422 break;
13423
13424 case EWPNPARENT:
13425 if(0!=(s=checkEWpn(ri->ewpn)))
13426 (((weapon*)(s))->parentid)= ( (get_qr(qr_OLDEWPNPARENT)) ? value / 10000 : value );
13427
13428 break;
13429
13430 case EWPNSCRIPT:
13431
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1621 times.
1621 if(0!=(s=checkEWpn(ri->ewpn)))
13432 {
13433 1621 (((weapon*)(s))->weaponscript)=vbound(value/10000,0,NUMSCRIPTWEAPONS-1);
13434
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1621 times.
1621 if ( get_qr(qr_CLEARINITDONSCRIPTCHANGE))
13435 {
13436
2/2
✓ Branch 0 taken 12968 times.
✓ Branch 1 taken 1621 times.
14589 for(int32_t q=0; q<8; q++)
13437 12968 (((weapon*)(s))->weap_initd[q]) = 0;
13438 1621 }
13439 1621 on_reassign_script_engine_data(ScriptType::Ewpn, ri->ewpn);
13440 1621 }
13441 1621 break;
13442
13443 case EWPNFALLCLK:
13444 if(0!=(s=checkEWpn(ri->ewpn)))
13445 {
13446 if(((weapon*)(s))->fallclk != 0 && value == 0)
13447 {
13448 ((weapon*)(s))->cs = ((weapon*)(s))->o_cset;
13449 ((weapon*)(s))->tile = ((weapon*)(s))->o_tile;
13450 }
13451 else if(((weapon*)(s))->fallclk == 0 && value != 0) ((weapon*)(s))->o_cset = ((weapon*)(s))->cs;
13452 ((weapon*)(s))->fallclk = vbound(value/10000,0,70);
13453 }
13454 break;
13455 case EWPNFALLCMB:
13456 if(0!=(s=checkEWpn(ri->ewpn)))
13457 {
13458 ((weapon*)(s))->fallCombo = vbound(value/10000,0,MAXCOMBOS-1);
13459 }
13460 break;
13461 case EWPNDROWNCLK:
13462 if(0!=(s=checkEWpn(ri->ewpn)))
13463 {
13464 if(((weapon*)(s))->drownclk != 0 && value == 0)
13465 {
13466 ((weapon*)(s))->cs = ((weapon*)(s))->o_cset;
13467 ((weapon*)(s))->tile = ((weapon*)(s))->o_tile;
13468 }
13469 else if(((weapon*)(s))->drownclk == 0 && value != 0) ((weapon*)(s))->o_cset = ((weapon*)(s))->cs;
13470 ((weapon*)(s))->drownclk = vbound(value/10000,0,70);
13471 }
13472 break;
13473 case EWPNDROWNCMB:
13474 if(0!=(s=checkEWpn(ri->ewpn)))
13475 {
13476 ((weapon*)(s))->drownCombo = vbound(value/10000,0,MAXCOMBOS-1);
13477 }
13478 break;
13479 case EWPNFAKEZ:
13480 if(0!=(s=checkEWpn(ri->ewpn)))
13481 {
13482 ((weapon*)s)->fakez=get_qr(qr_SPRITEXY_IS_FLOAT) ? zslongToFix(value) : zfix(value/10000);
13483 if(((weapon*)s)->fakez < 0) ((weapon*)s)->fakez = 0_zf;
13484 }
13485
13486 break;
13487
13488 case EWPNGLOWRAD:
13489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if(0!=(s=checkEWpn(ri->ewpn)))
13490 {
13491 4 ((weapon*)(s))->glowRad = vbound(value/10000,0,255);
13492 4 }
13493 4 break;
13494 case EWPNGLOWSHP:
13495 if(0!=(s=checkEWpn(ri->ewpn)))
13496 {
13497 ((weapon*)(s))->glowShape = vbound(value/10000,0,255);
13498 }
13499 break;
13500
13501 case EWPNUNBL:
13502 if(0!=(s=checkEWpn(ri->ewpn)))
13503 {
13504 ((weapon*)(s))->unblockable = (value/10000)&WPNUNB_ALL;
13505 }
13506 break;
13507
13508 case EWPNSHADOWSPR:
13509 if(0!=(s=checkEWpn(ri->ewpn)))
13510 {
13511 ((weapon*)(s))->spr_shadow = vbound(value/10000, 0, 255);
13512 }
13513 break;
13514 case EWSWHOOKED:
13515 break; //read-only
13516 case EWPNTIMEOUT:
13517 if(0!=(s=checkEWpn(ri->ewpn)))
13518 {
13519 ((weapon*)(s))->weap_timeout = vbound(value/10000,0,214748);
13520 }
13521 break;case EWPNDEATHITEM:
13522 if(0!=(s=checkEWpn(ri->ewpn)))
13523 {
13524 ((weapon*)(s))->death_spawnitem = vbound(value/10000,-1,MAXITEMS-1);
13525 }
13526 break;
13527 case EWPNDEATHDROPSET:
13528 if(0!=(s=checkEWpn(ri->ewpn)))
13529 {
13530 ((weapon*)(s))->death_spawndropset = vbound(value/10000,-1,MAXITEMDROPSETS-1);
13531 }
13532 break;
13533 case EWPNDEATHIPICKUP:
13534 if(0!=(s=checkEWpn(ri->ewpn)))
13535 {
13536 ((weapon*)(s))->death_item_pflags = value/10000;
13537 }
13538 break;
13539 case EWPNDEATHSPRITE:
13540 if(0!=(s=checkEWpn(ri->ewpn)))
13541 {
13542 ((weapon*)(s))->death_sprite = vbound(value/10000,-255,MAXWPNS-1);
13543 }
13544 break;
13545 case EWPNDEATHSFX:
13546 if(0!=(s=checkEWpn(ri->ewpn)))
13547 {
13548 ((weapon*)(s))->death_sfx = vbound(value/10000,0,WAV_COUNT);
13549 }
13550 break;
13551 case EWPNLIFTLEVEL:
13552 if(0!=(s=checkEWpn(ri->ewpn)))
13553 {
13554 ((weapon*)(s))->lift_level = vbound(value/10000,0,255);
13555 }
13556 break;
13557 case EWPNLIFTTIME:
13558 if(0!=(s=checkEWpn(ri->ewpn)))
13559 {
13560 ((weapon*)(s))->lift_time = vbound(value/10000,0,255);
13561 }
13562 break;
13563 case EWPNLIFTHEIGHT:
13564 if(0!=(s=checkEWpn(ri->ewpn)))
13565 {
13566 ((weapon*)(s))->lift_height = zslongToFix(value);
13567 }
13568 break;
13569
13570 ///----------------------------------------------------------------------------------------------------//
13571 //Screen Information
13572
13573 case SCREENSCRDATASIZE:
13574 {
13575 int index = map_screen_index(cur_map, ri->screenref);
13576 if (index < 0) break;
13577
13578 game->scriptDataResize(index, value/10000);
13579 break;
13580 }
13581
13582 case GAMEGUYCOUNTD:
13583 {
13584 int mi = mapind(cur_map, ri->d[rINDEX] / 10000);
13585 game->guys[mi] = value / 10000;
13586 break;
13587 }
13588
13589 ///----------------------------------------------------------------------------------------------------//
13590 //BottleTypes
13591
13592 case BOTTLENEXT:
13593 {
13594 if(bottletype* ptr = checkBottleData(ri->bottletyperef))
13595 {
13596 ptr->next_type = vbound(value/10000, 0, 64);
13597 }
13598 }
13599 break;
13600
13601 ///----------------------------------------------------------------------------------------------------//
13602 //Viewport
13603
13604 case VIEWPORT_TARGET:
13605 {
13606
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (auto s = ResolveBaseSprite(value))
13607 6 set_viewport_sprite(s);
13608 }
13609 6 break;
13610
13611 case VIEWPORT_MODE:
13612 {
13613 4 int val = value;
13614
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (BC::checkBounds(val, (int)ViewportMode::First, (int)ViewportMode::Last) != SH::_NoError)
13615 {
13616 break;
13617 }
13618
13619 4 viewport_mode = (ViewportMode)val;
13620 }
13621 4 break;
13622
13623 case VIEWPORT_X:
13624 {
13625 360 viewport.x = value / 10000;
13626 }
13627 360 break;
13628
13629 case VIEWPORT_Y:
13630 {
13631 360 viewport.y = value / 10000;
13632 }
13633 360 break;
13634
13635 case VIEWPORT_WIDTH:
13636 {
13637 int val = value / 10000;
13638 if (BC::checkBounds(val, 0, 256) != SH::_NoError)
13639 break;
13640
13641 viewport.w = val;
13642 }
13643 break;
13644
13645 case VIEWPORT_HEIGHT:
13646 {
13647 int val = value / 10000;
13648 if (BC::checkBounds(val, 0, 232) != SH::_NoError)
13649 break;
13650
13651 viewport.h = val;
13652 }
13653 break;
13654
13655 ///----------------------------------------------------------------------------------------------------//
13656 //Screen Variables
13657
13658 #define SET_SCREENDATA_VAR_INT32(member, str) \
13659 { \
13660 get_scr(ri->screenref)->member = vbound((value / 10000),-214747,214747); \
13661 } \
13662
13663 #define SET_SCREENDATA_VAR_INT16(member, str) \
13664 { \
13665 get_scr(ri->screenref)->member = vbound((value / 10000),0,32767); \
13666 } \
13667
13668 #define SET_SCREENDATA_VAR_BYTE(member, str) \
13669 { \
13670 get_scr(ri->screenref)->member = vbound((value / 10000),0,255); \
13671 } \
13672
13673 #define SET_SCREENDATA_BYTE_INDEX(member, str, indexbound) \
13674 { \
13675 int32_t indx = ri->d[rINDEX] / 10000; \
13676 get_scr(ri->screenref)->member[indx] = vbound((value / 10000),0,255); \
13677 }
13678
13679 ///max screen id is higher! vbound properly... -Z
13680 #define SET_SCREENDATA_LAYERSCREEN_INDEX(member, str, indexbound) \
13681 { \
13682 int32_t indx = ri->d[rINDEX] / 10000; \
13683 int32_t scrn_id = value/10000; \
13684 if ( FFCore.quest_format[vFFScript] < 11 ) ++indx; \
13685 if (BC::checkIndex(indx, 1, indexbound) != SH::_NoError) \
13686 { \
13687 } \
13688 else if ( scrn_id > MAPSCRS ) \
13689 { \
13690 Z_scripterrlog("Script attempted to use a mapdata->LayerScreen[%d].\n",scrn_id); \
13691 Z_scripterrlog("Valid Screen values are (0) through (%d).\n",MAPSCRS); \
13692 } \
13693 else get_scr(ri->screenref)->member[indx-1] = vbound((scrn_id),0,MAPSCRS); \
13694 }
13695
13696 #define SET_SCREENDATA_FLAG(member, str) \
13697 { \
13698 int32_t flag = (value/10000); \
13699 if ( flag != 0 ) \
13700 { \
13701 get_scr(ri->screenref)->member|=flag; \
13702 } \
13703 else get_scr(ri->screenref)->.member|= ~flag; \
13704 } \
13705
13706 #define SET_SCREENDATA_BOOL_INDEX(member, str, indexbound) \
13707 { \
13708 int32_t indx = ri->d[rINDEX] / 10000; \
13709 if(indx < 0 || indx > indexbound ) \
13710 { \
13711 Z_scripterrlog("Invalid Index passed to Screen->%s[]: %d\n", (indx), str); \
13712 break; \
13713 } \
13714 get_scr(ri->screenref)->member[indx] =( (value/10000) ? 1 : 0 ); \
13715 }
13716
13717 case SCREENDATAVALID:
13718 {
13719 SET_SCREENDATA_VAR_BYTE(valid, "Valid"); //b
13720 mark_current_region_handles_dirty();
13721 break;
13722 }
13723 case SCREENDATAGUY: SET_SCREENDATA_VAR_BYTE(guy, "Guy"); break; //b
13724 case SCREENDATASTRING: SET_SCREENDATA_VAR_INT32(str, "String"); break; //w
13725 case SCREENDATAROOM: SET_SCREENDATA_VAR_BYTE(room, "RoomType"); break; //b
13726 case SCREENDATAITEM:
13727 {
13728 auto v = vbound((value / 10000),-1,255);
13729 auto scr = get_scr(ri->screenref);
13730 if(v > -1)
13731 scr->item = v;
13732 scr->hasitem = v > -1;
13733 break;
13734 }
13735 case SCREENDATAHASITEM: SET_SCREENDATA_VAR_BYTE(hasitem, "HasItem"); break; //b
13736 case SCREENDATADOORCOMBOSET: SET_SCREENDATA_VAR_INT32(door_combo_set, "DoorComboSet"); break; //w
13737 case SCREENDATAWARPRETURNC: SET_SCREENDATA_VAR_INT32(warpreturnc, "WarpReturnC"); break; //w
13738 case SCREENDATASTAIRX: SET_SCREENDATA_VAR_BYTE(stairx, "StairsX"); break; //b
13739 case SCREENDATASTAIRY: SET_SCREENDATA_VAR_BYTE(stairy, "StairsY"); break; //b
13740 case SCREENDATAITEMX: SET_SCREENDATA_VAR_BYTE(itemx, "ItemX"); break; //itemx
13741 case SCREENDATAITEMY: SET_SCREENDATA_VAR_BYTE(itemy, "ItemY"); break; //itemy
13742 case SCREENDATACOLOUR: SET_SCREENDATA_VAR_INT32(color, "CSet"); break; //w
13743 case SCREENDATAENEMYFLAGS: SET_SCREENDATA_VAR_BYTE(flags11, "EnemyFlags"); break; //b
13744 case SCREENDATADOOR: SET_SCREENDATA_BYTE_INDEX(door, "Door", 3); break; //b, 4 of these
13745 case SCREENDATAEXITDIR: SET_SCREENDATA_VAR_BYTE(exitdir, "ExitDir"); break; //b
13746 case SCREENDATAPATTERN: SET_SCREENDATA_VAR_BYTE(pattern, "Pattern"); break; //b
13747 case SCREENDATAWARPARRIVALX: SET_SCREENDATA_VAR_BYTE(warparrivalx, "WarpArrivalX"); break; //b
13748 case SCREENDATAWARPARRIVALY: SET_SCREENDATA_VAR_BYTE(warparrivaly, "WarpArrivalY"); break; //b
13749 case SCREENDATASIDEWARPINDEX: SET_SCREENDATA_VAR_BYTE(sidewarpindex, "SideWarpIndex"); break; //b
13750 case SCREENDATAUNDERCOMBO: SET_SCREENDATA_VAR_INT32(undercombo, "Undercombo"); break; //w
13751 case SCREENDATAUNDERCSET: SET_SCREENDATA_VAR_BYTE(undercset, "UnderCSet"); break; //b
13752 case SCREENDATACATCHALL: SET_SCREENDATA_VAR_INT32(catchall, "Catchall"); break; //W
13753
13754 case SCREENDATACSENSITIVE: SET_SCREENDATA_VAR_BYTE(csensitive, "CSensitive"); break; //B
13755 case SCREENDATANORESET: SET_SCREENDATA_VAR_INT32(noreset, "NoReset"); break; //W
13756 case SCREENDATANOCARRY: SET_SCREENDATA_VAR_INT32(nocarry, "NoCarry"); break; //W
13757
13758 case SCREENDATATIMEDWARPTICS: SET_SCREENDATA_VAR_INT32(timedwarptics, "TimedWarpTimer"); break; //W
13759 case SCREENDATANEXTMAP: SET_SCREENDATA_VAR_BYTE(nextmap, "NextMap"); break; //B
13760 case SCREENDATANEXTSCREEN: SET_SCREENDATA_VAR_BYTE(nextscr, "NextScreen"); break; //B
13761 case SCREENDATAVIEWX: break;//SET_SCREENDATA_VAR_INT32(viewX, "ViewX"); break; //W
13762 case SCREENDATAVIEWY: break;//SET_SCREENDATA_VAR_INT32(viewY, "ViewY"); break; //W
13763 case SCREENDATASCREENWIDTH: break;//SET_SCREENDATA_VAR_BYTE(scrWidth, "Width"); break; //B
13764 case SCREENDATASCREENHEIGHT: break;//SET_SCREENDATA_VAR_BYTE(scrHeight, "Height"); break; //B
13765 case SCREENDATAENTRYX:
13766 {
13767 30 int32_t newx = vbound((value/10000),0,255);
13768 30 get_scr(ri->screenref)->entry_x = newx;
13769
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 20 times.
30 if ( get_qr(qr_WRITE_ENTRYPOINTS_AFFECTS_HEROCLASS) )
13770 {
13771 20 Hero.respawn_x = (zfix)(newx);
13772 20 }
13773 30 break;
13774 }
13775 case SCREENDATAENTRYY:
13776 {
13777
13778 30 int32_t newy = vbound((value/10000),0,175);
13779 30 get_scr(ri->screenref)->entry_y = newy;
13780
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 20 times.
30 if ( get_qr(qr_WRITE_ENTRYPOINTS_AFFECTS_HEROCLASS) )
13781 {
13782 20 Hero.respawn_y = (zfix)(newy);
13783 20 }
13784 30 break; //B
13785 }
13786
13787 case SCREENDATANUMFF:
13788 {
13789 break;
13790 }
13791
13792 case SCREENDATAFFINITIALISED:
13793 {
13794 int32_t indx = ri->d[rINDEX] / 10000;
13795 if (indx < 0 || indx > MAX_FFCID)
13796 {
13797 Z_scripterrlog("Invalid Index passed to Screen->%s[]: %d\n", (indx), "FFCRunning");
13798 break;
13799 }
13800 get_script_engine_data(ScriptType::FFC, indx).initialized = (value/10000) ? true : false;
13801 }
13802 break;
13803
13804 case SCREENDATASCRIPTENTRY:
13805 {
13806 Z_scripterrlog("Unimplemented: %s\n", "ScriptEntry");
13807 }
13808 break;
13809 case SCREENDATASCRIPTOCCUPANCY:
13810 {
13811 Z_scripterrlog("Unimplemented: %s\n", "ScriptOccupancy");
13812 }
13813 break;
13814 case SCREENDATASCRIPTEXIT:
13815 {
13816 Z_scripterrlog("Unimplemented: %s\n", "ExitScript");
13817 }
13818 break;
13819
13820 case SCREENDATAOCEANSFX:
13821 {
13822 int32_t v = vbound(value/10000, 0, 255);
13823 auto scr = get_scr(ri->screenref);
13824 if (scr == hero_scr && scr->oceansfx != v)
13825 {
13826 stop_sfx(scr->oceansfx);
13827 scr->oceansfx = v;
13828 cont_sfx(scr->oceansfx);
13829 }
13830 break;
13831 }
13832 case SCREENDATABOSSSFX: SET_SCREENDATA_VAR_BYTE(bosssfx, "BossSFX"); break; //B
13833 10 case SCREENDATASECRETSFX: SET_SCREENDATA_VAR_BYTE(secretsfx, "SecretSFX"); break; //B
13834 case SCREENDATAHOLDUPSFX: SET_SCREENDATA_VAR_BYTE(holdupsfx, "ItemSFX"); break; //B
13835 case SCREENDATASCREENMIDI:
13836 {
13837 get_scr(ri->screenref)->screen_midi = vbound((value / 10000)-(MIDIOFFSET_MAPSCR-MIDIOFFSET_ZSCRIPT),-1,32767);
13838 break;
13839 }
13840 case SCREENDATALENSLAYER: SET_SCREENDATA_VAR_BYTE(lens_layer, "LensLayer"); break; //B, OLD QUESTS ONLY?
13841
13842 case SCREENDATAGUYCOUNT:
13843 {
13844 int mi = mapind(cur_map, ri->screenref);
13845 if(mi > -1)
13846 game->guys[mi] = vbound(value/10000,10,0);
13847 break;
13848 }
13849 case SCREENDATAEXDOOR:
13850 {
13851 int mi = mapind(cur_map, ri->screenref);
13852 if(mi < 0) break;
13853 int dir = SH::read_stack(ri->sp+1) / 10000;
13854 int ind = SH::read_stack(ri->sp+0) / 10000;
13855 if(unsigned(dir) > 3)
13856 Z_scripterrlog("Invalid dir '%d' passed to 'Screen->SetExDoor()'; must be 0-3\n", dir);
13857 else if(unsigned(ind) > 7)
13858 Z_scripterrlog("Invalid index '%d' passed to 'Screen->SetExDoor()'; must be 0-7\n", ind);
13859 else
13860 set_xdoorstate_mi(mi, dir, ind);
13861 break;
13862 }
13863
13864 //These use the same method as SetScreenD
13865 case SCREENWIDTH:
13866 // FFScript::set_screenWidth(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)], value/10000);
13867 break;
13868
13869 case SCREENHEIGHT:
13870 // FFScript::set_screenHeight(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)], value/10000);
13871 break;
13872
13873 case SCREENVIEWX:
13874 // FFScript::set_screenViewX(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)], value/10000);
13875 break;
13876
13877 case SCREENVIEWY:
13878 // FFScript::set_screenViewY(&TheMaps[(ri->d[rINDEX2] / 10000) * MAPSCRS + (ri->d[rINDEX]/10000)], value/10000);
13879 break;
13880
13881 //These use the method of SetScreenEnemy
13882
13883 case GDD:
13884 write_array(game->global_d, ri->d[rINDEX] / 10000, value);
13885 break;
13886
13887 case SDDD:
13888 27297 FFScript::set_screen_d((ri->d[rINDEX])/10000 + ((get_currdmap())<<7), ri->d[rINDEX2]/10000, value);
13889 27297 break;
13890
13891 case SDDDD:
13892 536 FFScript::set_screen_d(ri->d[rINDEX2]/10000 + ((ri->d[rINDEX]/10000)<<7), ri->d[rEXP1]/10000, value);
13893 536 break;
13894
13895 case SCREENSCRIPT:
13896 {
13897 mapscr* scr = get_scr(ri->screenref);
13898
13899 if ( get_qr(qr_CLEARINITDONSCRIPTCHANGE))
13900 {
13901 for(int32_t q=0; q<8; q++)
13902 scr->screeninitd[q] = 0;
13903 }
13904
13905 scr->script=vbound(value/10000, 0, NUMSCRIPTSCREEN-1);
13906 on_reassign_script_engine_data(ScriptType::Screen, ri->screenref);
13907 break;
13908 }
13909
13910 case LIT:
13911 900 set_lights(value);
13912 900 break;
13913
13914 case WAVY:
13915 7396 wavy=value/10000;
13916 7396 break;
13917
13918 case QUAKE:
13919 6502 quakeclk=value/10000;
13920 6502 break;
13921
13922 case ROOMTYPE:
13923 get_scr(ri->screenref)->room=value/10000; break; //this probably doesn't work too well...
13924
13925 case ROOMDATA:
13926 11 get_scr(ri->screenref)->catchall=value/10000;
13927 11 break;
13928
13929 case PUSHBLOCKLAYER:
13930 mblock2.blockLayer=vbound(value/10000, 0, 6);
13931 break;
13932
13933 case PUSHBLOCKCOMBO:
13934 mblock2.bcombo=value/10000;
13935 break;
13936
13937 case PUSHBLOCKCSET:
13938 mblock2.cs=value/10000;
13939 mblock2.oldcset=value/10000;
13940 break;
13941
13942 case UNDERCOMBO:
13943 get_scr(ri->screenref)->undercombo=value/10000;
13944 break;
13945
13946 case UNDERCSET:
13947 get_scr(ri->screenref)->undercset=value/10000;
13948 break;
13949
13950 case SCREEN_DRAW_ORIGIN:
13951
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39294 times.
39294 if (BC::checkBounds(value, (int)DrawOrigin::First, (int)DrawOrigin::Last) != SH::_NoError)
13952 break;
13953
13954 39294 ri->screen_draw_origin = (DrawOrigin)value;
13955 39294 break;
13956
13957 case SCREEN_DRAW_ORIGIN_TARGET:
13958 {
13959
1/2
✓ Branch 0 taken 5310 times.
✗ Branch 1 not taken.
5310 if (ResolveBaseSprite(value))
13960 5310 ri->screen_draw_origin_target = value;
13961
13962 5310 break;
13963 }
13964
13965 ///----------------------------------------------------------------------------------------------------//
13966 //New Datatype Variables
13967
13968 ///----------------------------------------------------------------------------------------------------//
13969 //spritedata sp-> Variables
13970 case SPRITEDATATILE: SET_SPRITEDATA_VAR_INT(tile, "Tile"); break;
13971 case SPRITEDATAMISC: SET_SPRITEDATA_VAR_BYTE(misc, "Misc"); break;
13972 case SPRITEDATACSETS:
13973 {
13974 if(unsigned(ri->spritedataref) > (MAXWPNS-1) )
13975 {
13976 Z_scripterrlog("Invalid Sprite ID passed to spritedata->CSet: %d\n", (ri->spritedataref*10000));
13977 }
13978 else
13979 {
13980 wpnsbuf[ri->spritedataref].csets &= 0xF0;
13981 wpnsbuf[ri->spritedataref].csets |= vbound((value / 10000),0,15);
13982 }
13983 break;
13984 }
13985 case SPRITEDATAFLCSET:
13986 {
13987 if(unsigned(ri->spritedataref) > (MAXWPNS-1) )
13988 {
13989 Z_scripterrlog("Invalid Sprite ID passed to spritedata->FlashCSet: %d\n", (ri->spritedataref*10000));
13990 }
13991 else
13992 {
13993 wpnsbuf[ri->spritedataref].csets &= 0x0F;
13994 wpnsbuf[ri->spritedataref].csets |= vbound((value / 10000),0,15)<<4;
13995 }
13996 break;
13997 }
13998 case SPRITEDATAFRAMES: SET_SPRITEDATA_VAR_BYTE(frames, "Frames"); break;
13999 case SPRITEDATASPEED: SET_SPRITEDATA_VAR_BYTE(speed, "Speed"); break;
14000 case SPRITEDATATYPE: SET_SPRITEDATA_VAR_BYTE(type, "Type"); break;
14001
14002 ///----------------------------------------------------------------------------------------------------//
14003 //mapdata m-> Variables
14004 //mapdata m-> Variables
14005
14006 #define SET_MAPDATA_VAR_INT32(member) \
14007 { \
14008 if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14009 { \
14010 m->member = vbound((value / 10000),-214747,214747); \
14011 } \
14012 break; \
14013 } \
14014
14015 #define SET_MAPDATA_VAR_INT16(member) \
14016 { \
14017 if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14018 { \
14019 m->member = vbound((value / 10000),0,32767); \
14020 } \
14021 break; \
14022 } \
14023
14024 #define SET_MAPDATA_VAR_BYTE(member) \
14025 { \
14026 if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14027 { \
14028 m->member = vbound((value / 10000),0,255); \
14029 } \
14030 break; \
14031 } \
14032
14033 #define SET_MAPDATA_VAR_INDEX32(member, indexbound) \
14034 { \
14035 int32_t indx = ri->d[rINDEX] / 10000; \
14036 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
14037 { \
14038 } \
14039 else if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14040 { \
14041 m->member[indx] = vbound((value / 10000),-214747,214747); \
14042 } \
14043 break; \
14044 } \
14045
14046 #define SET_MAPDATA_VAR_INDEX16(member, indexbound) \
14047 { \
14048 int32_t indx = ri->d[rINDEX] / 10000; \
14049 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
14050 { \
14051 } \
14052 else if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14053 { \
14054 m->member[indx] = vbound((value / 10000),-32767,32767); \
14055 } \
14056 break; \
14057 } \
14058
14059 #define SET_MAPDATA_BYTE_INDEX(member, indexbound) \
14060 { \
14061 int32_t indx = ri->d[rINDEX] / 10000; \
14062 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
14063 { \
14064 } \
14065 else if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14066 { \
14067 m->member[indx] = vbound((value / 10000),0,255); \
14068 } \
14069 break; \
14070 }\
14071
14072 #define SET_MAPDATA_LAYER_INDEX(member, indexbound) \
14073 { \
14074 int32_t indx = ri->d[rINDEX] / 10000; \
14075 if ( FFCore.quest_format[vFFScript] < 11 ) ++indx; \
14076 if (BC::checkIndex(indx, 1, indexbound) != SH::_NoError) \
14077 { \
14078 } \
14079 else if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14080 { \
14081 m->member[indx-1] = vbound((value / 10000),0,255); \
14082 } \
14083 break; \
14084 } \
14085
14086 #define SET_MAPDATA_LAYERSCREEN_INDEX(member, indexbound) \
14087 { \
14088 int32_t indx = ri->d[rINDEX] / 10000; \
14089 if ( FFCore.quest_format[vFFScript] < 11 ) ++indx; \
14090 int32_t scrn_id = value/10000; \
14091 if (BC::checkIndex(indx, 1, indexbound) != SH::_NoError) \
14092 { \
14093 } \
14094 else if ( scrn_id > MAPSCRS ) \
14095 { \
14096 Z_scripterrlog("Script attempted to use a mapdata->LayerScreen[%d].\n",scrn_id); \
14097 Z_scripterrlog("Valid Screen values are (0) through (%d).\n",MAPSCRS); \
14098 } \
14099 else if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14100 { \
14101 m->member[indx-1] = vbound((scrn_id),0,MAPSCRS); \
14102 } \
14103 break; \
14104 }\
14105
14106 #define SET_MAPDATA_BOOL_INDEX(member, indexbound) \
14107 { \
14108 int32_t indx = ri->d[rINDEX] / 10000; \
14109 if (BC::checkIndex(indx, 0, indexbound) != SH::_NoError) \
14110 { \
14111 } \
14112 else if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14113 { \
14114 m->member[indx] =( (value/10000) ? 1 : 0 ); \
14115 } \
14116 break; \
14117 } \
14118
14119
14120 #define SET_FFC_MAPDATA_BOOL_INDEX(member, indexbound) \
14121 { \
14122 int32_t index = ri->d[rINDEX] / 10000; \
14123 if (auto handle = ResolveMapdataFFC(ri->mapsref, index)) \
14124 { \
14125 handle.ffc->member =( (value/10000) ? 1 : 0 ); \
14126 } \
14127 break; \
14128 } \
14129
14130 #define SET_MAPDATA_FLAG(member) \
14131 { \
14132 int32_t flag = (value/10000); \
14133 if (mapscr *m = ResolveMapdataScr(ri->mapsref)) \
14134 { \
14135 if ( flag != 0 ) \
14136 { \
14137 m->member|=flag; \
14138 } \
14139 else m->.member|= ~flag; \
14140 } \
14141 break; \
14142 } \
14143
14144
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 case MAPDATAVALID: SET_MAPDATA_VAR_BYTE(valid); break; //b
14145 case MAPDATAGUY: SET_MAPDATA_VAR_BYTE(guy); break; //b
14146 case MAPDATASTRING: SET_MAPDATA_VAR_INT32(str); break; //w
14147 case MAPDATAROOM: SET_MAPDATA_VAR_BYTE(room); break; //b
14148 case MAPDATAITEM:
14149 {
14150 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
14151 {
14152 auto v = vbound((value / 10000),-1,255);
14153 if(v > -1)
14154 m->item = v;
14155 m->hasitem = v > -1;
14156 }
14157 break;
14158 }
14159 case MAPDATAREGIONID:
14160 {
14161 370 int region_id = value / 10000;
14162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 370 times.
370 if (BC::checkBounds(region_id, 0, 9) != SH::_NoError)
14163 break;
14164
14165 370 auto result = decode_mapdata_ref(ri->mapsref);
14166
1/2
✓ Branch 0 taken 370 times.
✗ Branch 1 not taken.
370 if (result.scr)
14167 {
14168
1/2
✓ Branch 0 taken 370 times.
✗ Branch 1 not taken.
370 if (result.type == mapdata_type::CanonicalScreen)
14169 {
14170 370 Regions[result.scr->map].set_region_id(result.screen, region_id);
14171 370 }
14172 else
14173 {
14174 scripting_log_error_with_context("This may only be set for canonical screens");
14175 }
14176 370 }
14177 else
14178 {
14179 scripting_log_error_with_context("mapdata pointer is either invalid or uninitialised");
14180 }
14181 370 break;
14182 }
14183 case MAPDATAHASITEM: SET_MAPDATA_VAR_BYTE(hasitem); break; //b
14184 case MAPDATADOORCOMBOSET: SET_MAPDATA_VAR_INT32(door_combo_set); break; //w
14185 case MAPDATAWARPRETURNC: SET_MAPDATA_VAR_INT32(warpreturnc); break; //w
14186 case MAPDATASTAIRX: SET_MAPDATA_VAR_BYTE(stairx); break; //b
14187 case MAPDATASTAIRY: SET_MAPDATA_VAR_BYTE(stairy); break; //b
14188 case MAPDATAITEMX: SET_MAPDATA_VAR_BYTE(itemx); break; //itemx
14189 case MAPDATAITEMY: SET_MAPDATA_VAR_BYTE(itemy); break; //itemy
14190 case MAPDATACOLOUR: SET_MAPDATA_VAR_INT32(color); break; //w
14191 case MAPDATAENEMYFLAGS: SET_MAPDATA_VAR_BYTE(flags11); break; //b
14192 case MAPDATAEXITDIR: SET_MAPDATA_VAR_BYTE(exitdir); break; //b
14193 case MAPDATAPATTERN: SET_MAPDATA_VAR_BYTE(pattern); break; //b
14194 case MAPDATAWARPARRIVALX: SET_MAPDATA_VAR_BYTE(warparrivalx); break; //b
14195 case MAPDATAWARPARRIVALY: SET_MAPDATA_VAR_BYTE(warparrivaly); break; //b
14196
14197 case MAPDATASIDEWARPINDEX: SET_MAPDATA_VAR_BYTE(sidewarpindex); break; //b
14198 case MAPDATAUNDERCOMBO: SET_MAPDATA_VAR_INT32(undercombo); break; //w
14199 case MAPDATAUNDERCSET: SET_MAPDATA_VAR_BYTE(undercset); break; //b
14200 case MAPDATACATCHALL: SET_MAPDATA_VAR_INT32(catchall); break; //W
14201
14202 case MAPDATACSENSITIVE: SET_MAPDATA_VAR_BYTE(csensitive); break; //B
14203 case MAPDATANORESET: SET_MAPDATA_VAR_INT32(noreset); break; //W
14204 case MAPDATANOCARRY: SET_MAPDATA_VAR_INT32(nocarry); break; //W
14205 case MAPDATATIMEDWARPTICS: SET_MAPDATA_VAR_INT32(timedwarptics); break; //W
14206 case MAPDATANEXTMAP: SET_MAPDATA_VAR_BYTE(nextmap); break; //B
14207 case MAPDATANEXTSCREEN: SET_MAPDATA_VAR_BYTE(nextscr); break; //B
14208 case MAPDATAVIEWX: break;//SET_MAPDATA_VAR_INT32(viewX, "ViewX"); break; //W
14209 case MAPDATASCRIPT:
14210 {
14211 auto result = decode_mapdata_ref(ri->mapsref);
14212 if (result.scr)
14213 {
14214 if (result.current())
14215 {
14216 if (get_qr(qr_CLEARINITDONSCRIPTCHANGE))
14217 {
14218 for (int q=0; q<8; q++)
14219 result.scr->screeninitd[q] = 0;
14220 }
14221
14222 on_reassign_script_engine_data(ScriptType::Screen, ri->screenref);
14223 }
14224
14225 result.scr->script = vbound(value/10000, 0, NUMSCRIPTSCREEN-1);
14226 }
14227 else
14228 {
14229 Z_scripterrlog("Script attempted to use a mapdata->%s on an invalid pointer\n","Script");
14230 }
14231 break;
14232 }
14233 case MAPDATAVIEWY: break;//SET_MAPDATA_VAR_INT32(viewY, "ViewY"); break; //W
14234 case MAPDATASCREENWIDTH: break;//SET_MAPDATA_VAR_BYTE(scrWidth, "Width"); break; //B
14235 case MAPDATASCREENHEIGHT: break;//SET_MAPDATA_VAR_BYTE(scrHeight, "Height"); break; //B
14236 case MAPDATAENTRYX: SET_MAPDATA_VAR_BYTE(entry_x); break; //B
14237 case MAPDATAENTRYY: SET_MAPDATA_VAR_BYTE(entry_y); break; //B
14238
14239 //Number of ffcs that are in use (have valid data
14240 case MAPDATANUMFF:
14241 {
14242 break;
14243 }
14244
14245 case MAPDATAINTID:
14246 {
14247 9 int32_t index = (ri->d[rINDEX]/10000);
14248 9 int32_t dindex = ri->d[rINDEX2]/10000;
14249
14250
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (BC::checkBounds(dindex, 0, 7) != SH::_NoError)
14251 break;
14252
14253
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (auto handle = ResolveMapdataFFC(ri->mapsref, index))
14254 9 handle.ffc->initd[dindex] = value;
14255 9 break;
14256 }
14257
14258 case MAPDATASCRIPTENTRY:
14259 {
14260 Z_scripterrlog("Unimplemented: %s\n", "ScriptEntry");
14261 }
14262 break;
14263 case MAPDATASCRIPTOCCUPANCY:
14264 {
14265 Z_scripterrlog("Unimplemented: %s\n", "ScriptOccupancy");
14266 }
14267 break;
14268 case MAPDATASCRIPTEXIT:
14269 {
14270 Z_scripterrlog("Unimplemented: %s\n", "ExitScript");
14271 }
14272 break;
14273
14274 case MAPDATAOCEANSFX:
14275 {
14276 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
14277 {
14278 int32_t v = vbound(value/10000, 0, 255);
14279 if(m == hero_scr && m->oceansfx != v)
14280 {
14281 stop_sfx(m->oceansfx);
14282 m->oceansfx = v;
14283 cont_sfx(m->oceansfx);
14284 }
14285 else m->oceansfx = v;
14286 }
14287 break;
14288 }
14289 case MAPDATABOSSSFX: SET_MAPDATA_VAR_BYTE(bosssfx); break; //B
14290 case MAPDATASECRETSFX: SET_MAPDATA_VAR_BYTE(secretsfx); break; //B
14291 case MAPDATAHOLDUPSFX: SET_MAPDATA_VAR_BYTE(holdupsfx); break; //B
14292 case MAPDATASCREENMIDI:
14293 {
14294 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
14295 {
14296 m->screen_midi = vbound((value / 10000)-(MIDIOFFSET_MAPSCR-MIDIOFFSET_ZSCRIPT),-1,32767);
14297 }
14298 break;
14299 }
14300 case MAPDATALENSLAYER: SET_MAPDATA_VAR_BYTE(lens_layer); break; //B, OLD QUESTS ONLY?
14301
14302 case MAPDATASCRDATASIZE:
14303 {
14304 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
14305 {
14306 int index = get_ref_map_index(ri->mapsref);
14307 if (index < 0) break;
14308
14309 game->scriptDataResize(index, value/10000);
14310 }
14311 break;
14312 }
14313 case MAPDATAGUYCOUNT:
14314 {
14315 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
14316 {
14317 int mi = get_mi(ri->mapsref);
14318 if(mi > -1)
14319 {
14320 game->guys[mi] = vbound(value/10000,10,0);
14321 break;
14322 }
14323 }
14324 break;
14325 }
14326 case MAPDATAEXDOOR:
14327 {
14328 if (mapscr *m = ResolveMapdataScr(ri->mapsref))
14329 {
14330 int mi = get_mi(ri->mapsref);
14331 if(mi < 0) break;
14332 int dir = SH::read_stack(ri->sp+1) / 10000;
14333 int ind = SH::read_stack(ri->sp+0) / 10000;
14334 if(unsigned(dir) > 3)
14335 Z_scripterrlog("Invalid dir '%d' passed to 'mapdata->SetExDoor()'; must be 0-3\n", dir);
14336 else if(unsigned(ind) > 7)
14337 Z_scripterrlog("Invalid index '%d' passed to 'mapdata->SetExDoor()'; must be 0-7\n", ind);
14338 else
14339 set_xdoorstate_mi(mi, dir, ind);
14340 }
14341 break;
14342 }
14343
14344 ///----------------------------------------------------------------------------------------------------//
14345 //dmapdata dmd-> Variables
14346 case DMAPDATAMAP: //byte
14347 {
14348 DMaps[ri->dmapsref].map = ((byte)(value / 10000)) - 1; break;
14349 }
14350 case DMAPDATALEVEL: //word
14351 {
14352 DMaps[ri->dmapsref].level = ((word)(value / 10000)); break;
14353 }
14354 case DMAPDATAOFFSET: //char
14355 {
14356 DMaps[ri->dmapsref].xoff = ((char)(value / 10000)); break;
14357 }
14358 case DMAPDATACOMPASS: //byte
14359 {
14360 DMaps[ri->dmapsref].compass = ((byte)(value / 10000)); break;
14361 }
14362 case DMAPDATAPALETTE: //word
14363 {
14364 20 DMaps[ri->dmapsref].color= ((word)(value / 10000));
14365
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
20 if(ri->dmapsref == cur_dmap)
14366 {
14367 10 loadlvlpal(DMaps[ri->dmapsref].color);
14368 10 currcset = DMaps[ri->dmapsref].color;
14369 10 }
14370 20 break;
14371 }
14372 case DMAPDATAMIDI: //byte
14373 {
14374 DMaps[ri->dmapsref].midi = ((byte)((value / 10000)+MIDIOFFSET_DMAP)); break;
14375 }
14376 case DMAPDATACONTINUE: //byte
14377 {
14378 DMaps[ri->dmapsref].cont = ((byte)(value / 10000)); break;
14379 }
14380 case DMAPDATATYPE: //byte
14381 {
14382 DMaps[ri->dmapsref].type = (((byte)(value / 10000))&dmfTYPE) | (DMaps[ri->dmapsref].type&~dmfTYPE); break;
14383 }
14384 case DMAPSCRIPT: //byte
14385 {
14386 DMaps[ri->dmapsref].script = vbound((value / 10000),0,NUMSCRIPTSDMAP-1);
14387 on_reassign_script_engine_data(ScriptType::DMap, ri->dmapsref);
14388 break;
14389 }
14390 case DMAPDATASIDEVIEW: //byte, treat as bool
14391 {
14392 DMaps[ri->dmapsref].sideview = ((value) ? 1 : 0); break;
14393 }
14394 case DMAPDATAMUISCTRACK: //byte
14395 {
14396 DMaps[ri->dmapsref].tmusictrack= ((byte)(value / 10000)); break;
14397 }
14398 case DMAPDATASUBSCRA:
14399 {
14400 bool changed = DMaps[ri->dmapsref].active_subscreen != ((byte)(value / 10000));
14401 DMaps[ri->dmapsref].active_subscreen= ((byte)(value / 10000));
14402 if(changed&&ri->dmapsref==cur_dmap)
14403 update_subscreens();
14404 break;
14405 }
14406 case DMAPDATASUBSCRP:
14407 {
14408 5120 bool changed = DMaps[ri->dmapsref].passive_subscreen != ((byte)(value / 10000));
14409 5120 DMaps[ri->dmapsref].passive_subscreen= ((byte)(value / 10000));
14410
3/4
✓ Branch 0 taken 5120 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5110 times.
✓ Branch 3 taken 10 times.
5120 if(changed&&ri->dmapsref==cur_dmap)
14411 10 update_subscreens();
14412 5120 break;
14413 }
14414 case DMAPDATASUBSCRO:
14415 {
14416 bool changed = DMaps[ri->dmapsref].overlay_subscreen != ((byte)(value / 10000));
14417 DMaps[ri->dmapsref].overlay_subscreen = ((byte)(value / 10000));
14418 if(changed&&ri->dmapsref==cur_dmap)
14419 update_subscreens();
14420 break;
14421 }
14422 case DMAPDATAFLAGS: //int32_t
14423 {
14424 DMaps[ri->dmapsref].flags = (value / 10000); break;
14425 }
14426 case DMAPDATAMIRRDMAP:
14427 {
14428 DMaps[ri->dmapsref].mirrorDMap = vbound(value / 10000, -1, MAXDMAPS); break;
14429 }
14430 case DMAPDATALOOPSTART:
14431 {
14432 DMaps[ri->dmapsref].tmusic_loop_start = value;
14433 if (ri->dmapsref == cur_dmap)
14434 {
14435 if (FFCore.doing_dmap_enh_music(cur_dmap))
14436 {
14437 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
14438 }
14439 }
14440 break;
14441 }
14442 case DMAPDATALOOPEND:
14443 {
14444 DMaps[ri->dmapsref].tmusic_loop_end = value;
14445 if (ri->dmapsref == cur_dmap)
14446 {
14447 if (FFCore.doing_dmap_enh_music(cur_dmap))
14448 {
14449 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
14450 }
14451 }
14452 break;
14453 }
14454 case DMAPDATAXFADEIN:
14455 {
14456 DMaps[ri->dmapsref].tmusic_xfade_in = (value / 10000);
14457 break;
14458 }
14459 case DMAPDATAXFADEOUT:
14460 {
14461 DMaps[ri->dmapsref].tmusic_xfade_out = (value / 10000);
14462 if (DMaps[cur_dmap].tmusic[0]!=0 && strcmp(DMaps[ri->dmapsref].tmusic, zcmusic->filename) == 0)
14463 {
14464 zcmusic->fadeoutframes = (value / 10000);
14465 }
14466 break;
14467 }
14468 case DMAPDATAINTROSTRINGID:
14469 {
14470 DMaps[ri->dmapsref].intro_string_id = (value / 10000);
14471 break;
14472 }
14473 case MUSICUPDATECOND:
14474 {
14475 FFCore.music_update_cond = vbound(value / 10000, 0, 255);
14476 break;
14477 }
14478 case DMAPDATAASUBSCRIPT: //byte
14479 {
14480 DMaps[ri->dmapsref].active_sub_script = vbound((value / 10000),0,NUMSCRIPTSDMAP-1);
14481 on_reassign_script_engine_data(ScriptType::ScriptedActiveSubscreen, ri->dmapsref);
14482 break;
14483 }
14484 case DMAPDATAMAPSCRIPT: //byte
14485 {
14486 3225 DMaps[ri->dmapsref].onmap_script = vbound((value / 10000),0,NUMSCRIPTSDMAP-1);
14487 3225 on_reassign_script_engine_data(ScriptType::OnMap, ri->dmapsref);
14488 3225 break;
14489 }
14490 case DMAPDATAPSUBSCRIPT: //byte
14491 {
14492 FFScript::deallocateAllScriptOwned(ScriptType::ScriptedPassiveSubscreen, ri->dmapsref);
14493 word val = vbound((value / 10000),0,NUMSCRIPTSDMAP-1);
14494 if (FFCore.doscript(ScriptType::ScriptedPassiveSubscreen) && ri->dmapsref == cur_dmap && val == DMaps[ri->dmapsref].passive_sub_script)
14495 break;
14496 DMaps[ri->dmapsref].passive_sub_script = val;
14497 if(ri->dmapsref == cur_dmap)
14498 {
14499 FFCore.doscript(ScriptType::ScriptedPassiveSubscreen) = val != 0;
14500 };
14501 break;
14502 }
14503
14504 ///----------------------------------------------------------------------------------------------------//
14505 //messagedata msgd-> Variables
14506
14507
14508 case MESSAGEDATANEXT: //W
14509 {
14510 28 int32_t ID = ri->zmsgref;
14511
14512
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
28 if(BC::checkMessage(ID) != SH::_NoError)
14513 break;
14514 else
14515 28 MsgStrings[ID].nextstring = vbound((value/10000), 0, (msg_count-1));
14516 28 break;
14517 }
14518
14519 case MESSAGEDATATILE: //W
14520 {
14521 int32_t ID = ri->zmsgref;
14522
14523 if(BC::checkMessage(ID) != SH::_NoError)
14524 break;
14525 else
14526 MsgStrings[ID].tile = vbound((value/10000), 0, (NEWMAXTILES));
14527 break;
14528 }
14529
14530 case MESSAGEDATACSET: //b
14531 {
14532 int32_t ID = ri->zmsgref;
14533
14534 if(BC::checkMessage(ID) != SH::_NoError)
14535 break;
14536 else
14537 MsgStrings[ID].cset = ((byte)vbound((value/10000), 0, 15));
14538 break;
14539 }
14540 case MESSAGEDATATRANS: //BOOL
14541 {
14542 int32_t ID = ri->zmsgref;
14543
14544 if(BC::checkMessage(ID) != SH::_NoError)
14545 break;
14546 else
14547 (MsgStrings[ID].trans) = ((value)?true:false);
14548 break;
14549 }
14550 case MESSAGEDATAFONT: //B
14551 {
14552 int32_t ID = ri->zmsgref;
14553
14554 if(BC::checkMessage(ID) != SH::_NoError)
14555 break;
14556 else
14557 MsgStrings[ID].font = ((byte)vbound((value/10000), 0, 255));
14558 break;
14559 }
14560 case MESSAGEDATAX: //SHORT
14561 {
14562 24 int32_t ID = ri->zmsgref;
14563
14564
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if(BC::checkMessage(ID) != SH::_NoError)
14565 break;
14566 else
14567 24 MsgStrings[ID].x = ((int16_t)vbound((value/10000), SHRT_MIN, SHRT_MAX));
14568 24 break;
14569 }
14570 case MESSAGEDATAY: //SHORT
14571 {
14572 24 int32_t ID = ri->zmsgref;
14573
14574
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if(BC::checkMessage(ID) != SH::_NoError)
14575 break;
14576 else
14577 24 MsgStrings[ID].y = ((int16_t)vbound((value/10000), SHRT_MIN, SHRT_MAX));
14578 24 break;
14579 }
14580 case MESSAGEDATAW: //UNSIGNED SHORT
14581 {
14582 int32_t ID = ri->zmsgref;
14583
14584 if(BC::checkMessage(ID) != SH::_NoError)
14585 break;
14586 else
14587 MsgStrings[ID].w = ((uint16_t)vbound((value/10000), 0, USHRT_MAX));
14588 break;
14589 }
14590 case MESSAGEDATAH: //UNSIGNED SHORT
14591 {
14592 int32_t ID = ri->zmsgref;
14593
14594 if(BC::checkMessage(ID) != SH::_NoError)
14595 break;
14596 else
14597 MsgStrings[ID].h = ((uint16_t)vbound((value/10000), 0, USHRT_MAX));
14598 break;
14599 }
14600 case MESSAGEDATASFX: //BYTE
14601 {
14602 24 int32_t ID = ri->zmsgref;
14603
14604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if(BC::checkMessage(ID) != SH::_NoError)
14605 break;
14606 else
14607 24 MsgStrings[ID].sfx = ((byte)vbound((value/10000), 0, 255));
14608 24 break;
14609 }
14610 case MESSAGEDATALISTPOS: //WORD
14611 {
14612 int32_t ID = ri->zmsgref;
14613
14614 if(BC::checkMessage(ID) != SH::_NoError)
14615 break;
14616 else
14617 MsgStrings[ID].listpos = vbound((value/10000), 1, (msg_count-1));
14618 break;
14619 }
14620 case MESSAGEDATAVSPACE: //BYTE
14621 {
14622 int32_t ID = ri->zmsgref;
14623
14624 if(BC::checkMessage(ID) != SH::_NoError)
14625 break;
14626 else
14627 MsgStrings[ID].vspace = ((byte)vbound((value/10000), 0, 255));
14628 break;
14629 }
14630 case MESSAGEDATAHSPACE: //BYTE
14631 {
14632 int32_t ID = ri->zmsgref;
14633
14634 if(BC::checkMessage(ID) != SH::_NoError)
14635 break;
14636 else
14637 MsgStrings[ID].hspace = ((byte)vbound((value/10000), 0, 255));
14638 break;
14639 }
14640 case MESSAGEDATAFLAGS: //BYTE
14641 {
14642 int32_t ID = ri->zmsgref;
14643
14644 if(BC::checkMessage(ID) != SH::_NoError)
14645 break;
14646 else
14647 MsgStrings[ID].stringflags = ((byte)vbound((value/10000), 0, 255));
14648 break;
14649 }
14650 case MESSAGEDATAPORTTILE: //INT
14651 {
14652 int32_t ID = ri->zmsgref;
14653
14654 if(BC::checkMessage(ID) != SH::_NoError)
14655 break;
14656 else
14657 MsgStrings[ID].portrait_tile = vbound((value/10000), 0, (NEWMAXTILES));
14658 break;
14659 }
14660 case MESSAGEDATAPORTCSET: //BYTE
14661 {
14662 int32_t ID = ri->zmsgref;
14663
14664 if(BC::checkMessage(ID) != SH::_NoError)
14665 break;
14666 else
14667 MsgStrings[ID].portrait_cset = ((byte)vbound((value/10000), 0, 15));
14668 break;
14669 }
14670 case MESSAGEDATAPORTX: //BYTE
14671 {
14672 int32_t ID = ri->zmsgref;
14673
14674 if(BC::checkMessage(ID) != SH::_NoError)
14675 break;
14676 else
14677 MsgStrings[ID].portrait_x = ((byte)vbound((value/10000), 0, 255));
14678 break;
14679 }
14680 case MESSAGEDATAPORTY: //BYTE
14681 {
14682 int32_t ID = ri->zmsgref;
14683
14684 if(BC::checkMessage(ID) != SH::_NoError)
14685 break;
14686 else
14687 MsgStrings[ID].portrait_y = ((byte)vbound((value/10000), 0, 255));
14688 break;
14689 }
14690 case MESSAGEDATAPORTWID: //BYTE
14691 {
14692 int32_t ID = ri->zmsgref;
14693
14694 if(BC::checkMessage(ID) != SH::_NoError)
14695 break;
14696 else
14697 MsgStrings[ID].portrait_tw = ((byte)vbound((value/10000), 0, 16));
14698 break;
14699 }
14700 case MESSAGEDATAPORTHEI: //BYTE
14701 {
14702 int32_t ID = ri->zmsgref;
14703
14704 if(BC::checkMessage(ID) != SH::_NoError)
14705 break;
14706 else
14707 MsgStrings[ID].portrait_th = ((byte)vbound((value/10000), 0, 14));
14708 break;
14709 }
14710
14711 ///----------------------------------------------------------------------------------------------------//
14712 //combodata cd-> Setter Variables
14713 //newcombo
14714 #define SET_COMBO_VAR_INT(member) \
14715 { \
14716 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14717 { \
14718 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14719 } \
14720 else \
14721 { \
14722 screen_combo_modify_pre(ri->combosref); \
14723 combobuf[ri->combosref].member = vbound((value / 10000),0,214747); \
14724 screen_combo_modify_post(ri->combosref); \
14725 \
14726 } \
14727 } \
14728
14729 #define SET_COMBO_VAR_DWORD(member) \
14730 { \
14731 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14732 { \
14733 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14734 } \
14735 else \
14736 { \
14737 screen_combo_modify_pre(ri->combosref); \
14738 combobuf[ri->combosref].member = vbound((value / 10000),0,32767); \
14739 screen_combo_modify_post(ri->combosref); \
14740 } \
14741 } \
14742
14743 #define SET_COMBO_VAR_BYTE(member) \
14744 { \
14745 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14746 { \
14747 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14748 } \
14749 else \
14750 { \
14751 screen_combo_modify_pre(ri->combosref); \
14752 combobuf[ri->combosref].member = vbound((value / 10000),0,255); \
14753 screen_combo_modify_post(ri->combosref); \
14754 } \
14755 } \
14756
14757 #define SET_COMBO_FLAG(member) \
14758 { \
14759 int32_t flag = (value/10000); \
14760 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14761 { \
14762 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14763 } \
14764 else \
14765 { \
14766 if ( flag != 0 ) \
14767 { \
14768 combobuf[ri->combosref].member|=flag; \
14769 } \
14770 else combobuf[ri->combosref].member|= ~flag; \
14771 } \
14772 } \
14773
14774 //comboclass
14775 #define SET_COMBOCLASS_VAR_INT(member) \
14776 { \
14777 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14778 { \
14779 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14780 } \
14781 else \
14782 { \
14783 combo_class_buf[combobuf[ri->combosref].type].member = vbound((value / 10000),0,214747); \
14784 } \
14785 } \
14786
14787 #define SET_COMBOCLASS_VAR_DWORD(member) \
14788 { \
14789 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14790 { \
14791 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14792 } \
14793 else \
14794 { \
14795 combo_class_buf[combobuf[ri->combosref].type].member = vbound((value / 10000),0,32767); \
14796 } \
14797 } \
14798
14799 #define SET_COMBOCLASS_VAR_BYTE(member) \
14800 { \
14801 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14802 { \
14803 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14804 } \
14805 else \
14806 { \
14807 combo_class_buf[combobuf[ri->combosref].type].member = vbound((value / 10000),0,255); \
14808 } \
14809 } \
14810
14811 #define SET_COMBOCLASS_BYTE_INDEX(member, indexbound) \
14812 { \
14813 int32_t indx = ri->d[rINDEX] / 10000; \
14814 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14815 { \
14816 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14817 } \
14818 else if ( indx < 0 || indx > indexbound ) \
14819 { \
14820 scripting_log_error_with_context("Invalid Array Index: {}", indx); \
14821 } \
14822 else \
14823 { \
14824 combo_class_buf[combobuf[ri->combosref].type].member[indx] = vbound((value / 10000),0,255); \
14825 } \
14826 }
14827
14828 #define SET_COMBOCLASS_FLAG(member, str) \
14829 { \
14830 int32_t flag = (value/10000); \
14831 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) ) \
14832 { \
14833 scripting_log_error_with_context("Invalid combodata ID: {}", (ri->combosref*10000)); \
14834 } \
14835 else \
14836 { \
14837 if ( flag != 0 ) \
14838 { \
14839 combo_class_buf[combobuf[ri->combosref].type].member|=flag; \
14840 } \
14841 else combo_class_buf[combobuf[ri->combosref].type].member|= ~flag; \
14842 } \
14843 } \
14844
14845 //NEWCOMBO STRUCT
14846 case COMBODTILE: SET_COMBO_VAR_INT(tile); break; //word
14847 case COMBODOTILE:
14848 {
14849 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
14850 {
14851 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
14852 }
14853 else
14854 {
14855 newcombo& cdata = combobuf[ri->combosref];
14856 cdata.o_tile = vbound((value / 10000),0,NEWMAXTILES);
14857 if(get_qr(qr_NEW_COMBO_ANIMATION))
14858 {
14859 cdata.tile = cdata.o_tile + ((1+cdata.skipanim)*cdata.cur_frame);
14860 if(int32_t rowoffset = TILEROW(cdata.tile)-TILEROW(cdata.o_tile))
14861 {
14862 cdata.tile += cdata.skipanimy * rowoffset * TILES_PER_ROW;
14863 }
14864 combo_caches::drawing.refresh(ri->combosref);
14865 }
14866 }
14867 break;
14868 }
14869 case COMBODFRAME: SET_COMBO_VAR_BYTE(cur_frame); break; //char
14870 case COMBODACLK: SET_COMBO_VAR_BYTE(aclk); break; //char
14871 case COMBODATASCRIPT: SET_COMBO_VAR_DWORD(script); break; //word
14872 case COMBODASPEED: SET_COMBO_VAR_BYTE(speed); break; //char
14873 case COMBODFLIP: SET_COMBO_VAR_BYTE(flip); break; //char
14874 case COMBODWALK:
14875 {
14876 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
14877 {
14878 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
14879 }
14880 else
14881 {
14882 combobuf[ri->combosref].walk &= ~0x0F;
14883 combobuf[ri->combosref].walk |= (value / 10000)&0x0F;
14884 }
14885 break;
14886 }
14887 case COMBODEFFECT:
14888 {
14889 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
14890 {
14891 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
14892 }
14893 else
14894 {
14895 combobuf[ri->combosref].walk &= ~0xF0;
14896 combobuf[ri->combosref].walk |= ((value / 10000)&0x0F)<<4;
14897 }
14898 break;
14899 }
14900 case COMBODTYPE:
14901 {
14902 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
14903 {
14904 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
14905 }
14906 else
14907 {
14908 screen_combo_modify_pre(ri->combosref);
14909 combobuf[ri->combosref].type = vbound((value / 10000),0,255);
14910 screen_combo_modify_post(ri->combosref);
14911 }
14912 break;
14913 }
14914 case COMBODCSET:
14915 {
14916 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
14917 {
14918 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
14919 }
14920 else
14921 {
14922 screen_combo_modify_pre(ri->combosref);
14923 int8_t v = vbound(value, -8, 7);
14924 combobuf[ri->combosref].csets &= ~0xF;
14925 combobuf[ri->combosref].csets |= v;
14926 screen_combo_modify_post(ri->combosref);
14927 }
14928 break;
14929 }
14930 case COMBODCSET2FLAGS:
14931 {
14932 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
14933 {
14934 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
14935 }
14936 else
14937 {
14938 screen_combo_modify_pre(ri->combosref);
14939 combobuf[ri->combosref].csets &= 0xF;
14940 combobuf[ri->combosref].csets |= (value&0xF)<<4;
14941 screen_combo_modify_post(ri->combosref);
14942 }
14943 break;
14944 }
14945 case COMBODFOO: break; //W
14946 case COMBODFRAMES: SET_COMBO_VAR_BYTE(frames); break; //C
14947 case COMBODNEXTD: SET_COMBO_VAR_INT(nextcombo); break; //W
14948 case COMBODNEXTC: SET_COMBO_VAR_BYTE(nextcset); break; //C
14949 case COMBODFLAG: SET_COMBO_VAR_BYTE(flag); break; //C
14950 case COMBODSKIPANIM: SET_COMBO_VAR_BYTE(skipanim); break; //C
14951 case COMBODNEXTTIMER: SET_COMBO_VAR_DWORD(nexttimer); break; //W
14952 case COMBODAKIMANIMY: SET_COMBO_VAR_BYTE(skipanimy); break; //C
14953 case COMBODANIMFLAGS: SET_COMBO_VAR_BYTE(animflags); break; //C
14954 case COMBODUSRFLAGS: SET_COMBO_VAR_INT(usrflags); break; //LONG
14955 case COMBODTRIGGERITEM:
14956 {
14957 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
14958 {
14959 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
14960 }
14961 else if(auto* trig = get_first_combo_trigger())
14962 trig->triggeritem = vbound(value/10000,0,255);
14963 break;
14964 }
14965 case COMBODTRIGGERTIMER:
14966 {
14967 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
14968 {
14969 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
14970 }
14971 else
14972 {
14973 screen_combo_modify_pre(ri->combosref);
14974 if(auto* trig = get_first_combo_trigger())
14975 trig->trigtimer = vbound(value/10000,0,65535);
14976 screen_combo_modify_post(ri->combosref);
14977 }
14978 break;
14979 }
14980 case COMBODTRIGGERSFX:
14981 {
14982 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
14983 {
14984 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
14985 }
14986 else if(auto* trig = get_first_combo_trigger())
14987 trig->trigsfx = vbound(value/10000,0,255);
14988 break;
14989 }
14990 case COMBODTRIGGERCHANGECMB:
14991 {
14992 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
14993 {
14994 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
14995 }
14996 else if(auto* trig = get_first_combo_trigger())
14997 trig->trigchange = vbound(value/10000,-65535,65535);
14998 break;
14999 }
15000 case COMBODTRIGGERPROX:
15001 {
15002 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15003 {
15004 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15005 }
15006 else if(auto* trig = get_first_combo_trigger())
15007 trig->trigprox = vbound(value/10000,0,65535);
15008 break;
15009 }
15010 case COMBODTRIGGERLIGHTBEAM:
15011 {
15012 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15013 {
15014 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15015 }
15016 else if(auto* trig = get_first_combo_trigger())
15017 trig->triglbeam = vbound(value/10000,0,32);
15018 break;
15019 }
15020 case COMBODTRIGGERCTR:
15021 {
15022 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15023 {
15024 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15025 }
15026 else if(auto* trig = get_first_combo_trigger())
15027 trig->trigctr = vbound(value/10000, sscMIN, MAX_COUNTERS-1);
15028 break;
15029 }
15030 case COMBODTRIGGERCTRAMNT:
15031 {
15032 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15033 {
15034 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15035 }
15036 else if(auto* trig = get_first_combo_trigger())
15037 trig->trigctramnt = vbound(value/10000, -65535, 65535);
15038 break;
15039 }
15040
15041 case COMBODTRIGGERCOOLDOWN:
15042 {
15043 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15044 {
15045 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15046 }
15047 else if(auto* trig = get_first_combo_trigger())
15048 trig->trigcooldown = vbound(value/10000, 0, 255);
15049 break;
15050 }
15051 case COMBODTRIGGERCOPYCAT:
15052 {
15053 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15054 {
15055 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15056 }
15057 else if(auto* trig = get_first_combo_trigger())
15058 trig->trigcopycat = vbound(value/10000, 0, 255);
15059 break;
15060 }
15061 case COMBODTRIGITEMPICKUP:
15062 {
15063 const int32_t allowed_pflags = ipHOLDUP | ipTIMER | ipSECRETS | ipCANGRAB;
15064 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15065 {
15066 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15067 }
15068 else if(auto* trig = get_first_combo_trigger())
15069 trig->spawnip = (value/10000)&allowed_pflags;
15070 break;
15071 }
15072 case COMBODTRIGEXSTATE:
15073 {
15074 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15075 {
15076 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15077 }
15078 else if(auto* trig = get_first_combo_trigger())
15079 trig->exstate = vbound(value/10000, -1, 31);
15080 break;
15081 }
15082 case COMBODTRIGEXDOORDIR:
15083 {
15084 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15085 {
15086 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15087 }
15088 else if(auto* trig = get_first_combo_trigger())
15089 trig->exdoor_dir = vbound(value/10000, -1, 3);
15090 break;
15091 }
15092 case COMBODTRIGEXDOORIND:
15093 {
15094 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15095 {
15096 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15097 }
15098 else if(auto* trig = get_first_combo_trigger())
15099 trig->exdoor_ind = vbound(value/10000, 0, 7);
15100 break;
15101 }
15102 case COMBODTRIGSPAWNENEMY:
15103 {
15104 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15105 {
15106 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15107 }
15108 else if(auto* trig = get_first_combo_trigger())
15109 trig->spawnenemy = vbound(value/10000, 0, 511);
15110 break;
15111 }
15112 case COMBODTRIGSPAWNITEM:
15113 {
15114 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15115 {
15116 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15117 }
15118 else if(auto* trig = get_first_combo_trigger())
15119 trig->spawnitem = vbound(value/10000, -255, 255);
15120 break;
15121 }
15122 case COMBODTRIGCSETCHANGE:
15123 {
15124 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15125 {
15126 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15127 }
15128 else if(auto* trig = get_first_combo_trigger())
15129 trig->trigcschange = vbound(value/10000, -15, 15);
15130 break;
15131 }
15132 case COMBODTRIGLITEMS:
15133 {
15134 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15135 {
15136 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15137 }
15138 else if(auto* trig = get_first_combo_trigger())
15139 trig->trig_levelitems = (value/10000)&liALL;
15140 break;
15141 }
15142 case COMBODTRIGDMAPLVL:
15143 {
15144 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15145 {
15146 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15147 }
15148 else if(auto* trig = get_first_combo_trigger())
15149 trig->trigdmlevel = vbound(value/10000, -1, MAXLEVELS-1);
15150 break;
15151 }
15152 case COMBODTRIGTINTR:
15153 {
15154 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15155 {
15156 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15157 }
15158 else if(auto* trig = get_first_combo_trigger())
15159 trig->trigtint[0] = scripting_write_pal_color(vbound(value/10000, -scripting_max_color_val, scripting_max_color_val));
15160 break;
15161 }
15162 case COMBODTRIGTINTG:
15163 {
15164 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15165 {
15166 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15167 }
15168 else if(auto* trig = get_first_combo_trigger())
15169 trig->trigtint[1] = scripting_write_pal_color(vbound(value/10000, -scripting_max_color_val, scripting_max_color_val));
15170 break;
15171 }
15172 case COMBODTRIGTINTB:
15173 {
15174 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15175 {
15176 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15177 }
15178 else if(auto* trig = get_first_combo_trigger())
15179 trig->trigtint[2] = scripting_write_pal_color(vbound(value/10000, -scripting_max_color_val, scripting_max_color_val));
15180 break;
15181 }
15182 case COMBODTRIGLVLPAL:
15183 {
15184 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15185 {
15186 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15187 }
15188 else if(auto* trig = get_first_combo_trigger())
15189 trig->triglvlpalette = vbound(value/10000, -1, 512);
15190 break;
15191 }
15192 case COMBODTRIGBOSSPAL:
15193 {
15194 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15195 {
15196 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15197 }
15198 else if(auto* trig = get_first_combo_trigger())
15199 trig->trigbosspalette = vbound(value/10000, -1, 29);
15200 break;
15201 }
15202 case COMBODTRIGQUAKETIME:
15203 {
15204 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15205 {
15206 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15207 }
15208 else if(auto* trig = get_first_combo_trigger())
15209 trig->trigquaketime = zc_max(value/10000, -1);
15210 break;
15211 }
15212 case COMBODTRIGWAVYTIME:
15213 {
15214 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15215 {
15216 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15217 }
15218 else if(auto* trig = get_first_combo_trigger())
15219 trig->trigwavytime = zc_max(value/10000, -1);
15220 break;
15221 }
15222 case COMBODTRIGSWORDJINX:
15223 {
15224 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15225 {
15226 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15227 }
15228 else if(auto* trig = get_first_combo_trigger())
15229 trig->trig_swjinxtime = zc_max(value/10000, -2);
15230 break;
15231 }
15232 case COMBODTRIGITEMJINX:
15233 {
15234 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15235 {
15236 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15237 }
15238 else if(auto* trig = get_first_combo_trigger())
15239 trig->trig_itmjinxtime = zc_max(value/10000, -2);
15240 break;
15241 }
15242 case COMBODTRIGSHIELDJINX:
15243 {
15244 if (ri->combosref < 0 || ri->combosref >(MAXCOMBOS - 1))
15245 {
15246 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15247 }
15248 else if(auto* trig = get_first_combo_trigger())
15249 trig->trig_shieldjinxtime = zc_max(value / 10000, -2);
15250 break;
15251 }
15252 case COMBODTRIGSTUN:
15253 {
15254 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15255 {
15256 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15257 }
15258 else if(auto* trig = get_first_combo_trigger())
15259 trig->trig_stuntime = zc_max(value/10000, -2);
15260 break;
15261 }
15262 case COMBODTRIGBUNNY:
15263 {
15264 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15265 {
15266 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15267 }
15268 else if(auto* trig = get_first_combo_trigger())
15269 trig->trig_bunnytime = zc_max(value/10000, -2);
15270 break;
15271 }
15272 case COMBODTRIGPUSHTIME:
15273 {
15274 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15275 {
15276 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15277 }
15278 else if(auto* trig = get_first_combo_trigger())
15279 trig->trig_pushtime = vbound(value/10000, 0, 255);
15280 break;
15281 }
15282 case COMBODLIFTGFXCOMBO:
15283 {
15284 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15285 {
15286 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15287 }
15288 else combobuf[ri->combosref].liftcmb = vbound(value/10000, 0, MAXCOMBOS);
15289 break;
15290 }
15291 case COMBODLIFTGFXCCSET:
15292 {
15293 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15294 {
15295 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15296 }
15297 else combobuf[ri->combosref].liftcs = vbound(value/10000, 0, 13);
15298 break;
15299 }
15300 case COMBODLIFTUNDERCMB:
15301 {
15302 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15303 {
15304 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15305 }
15306 else combobuf[ri->combosref].liftundercmb = vbound(value/10000, 0, MAXCOMBOS);
15307 break;
15308 }
15309 case COMBODLIFTUNDERCS:
15310 {
15311 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15312 {
15313 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15314 }
15315 else combobuf[ri->combosref].liftundercs = vbound(value/10000, 0, 13);
15316 break;
15317 }
15318 case COMBODLIFTDAMAGE:
15319 {
15320 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15321 {
15322 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15323 }
15324 else combobuf[ri->combosref].liftdmg = vbound(value/10000, 0, 255);
15325 break;
15326 }
15327 case COMBODLIFTLEVEL:
15328 {
15329 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15330 {
15331 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15332 }
15333 else combobuf[ri->combosref].liftlvl = vbound(value/10000, 0, 255);
15334 break;
15335 }
15336 case COMBODLIFTITEM:
15337 {
15338 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15339 {
15340 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15341 }
15342 else combobuf[ri->combosref].liftitm = vbound(value/10000, 0, 255);
15343 break;
15344 }
15345 case COMBODLIFTGFXTYPE:
15346 {
15347 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15348 {
15349 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15350 }
15351 else combobuf[ri->combosref].liftgfx = vbound(value/10000, 0, 2);
15352 break;
15353 }
15354 case COMBODLIFTGFXSPRITE:
15355 {
15356 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15357 {
15358 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15359 }
15360 else combobuf[ri->combosref].liftsprite = vbound(value/10000, 0, 255);
15361 break;
15362 }
15363 case COMBODLIFTSFX:
15364 {
15365 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15366 {
15367 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15368 }
15369 else combobuf[ri->combosref].liftsfx = vbound(value/10000, 0, 255);
15370 break;
15371 }
15372 case COMBODLIFTBREAKSPRITE:
15373 {
15374 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15375 {
15376 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15377 }
15378 else combobuf[ri->combosref].liftbreaksprite = vbound(value/10000, -4, 255);
15379 break;
15380 }
15381 case COMBODLIFTBREAKSFX:
15382 {
15383 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15384 {
15385 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15386 }
15387 else combobuf[ri->combosref].liftbreaksfx = vbound(value/10000, 0, 255);
15388 break;
15389 }
15390 case COMBODLIFTHEIGHT:
15391 {
15392 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15393 {
15394 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15395 }
15396 else combobuf[ri->combosref].lifthei = vbound(value/10000, 0, 255);
15397 break;
15398 }
15399 case COMBODLIFTTIME:
15400 {
15401 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15402 {
15403 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15404 }
15405 else combobuf[ri->combosref].lifttime = vbound(value/10000, 0, 255);
15406 break;
15407 }
15408 case COMBODLIFTLIGHTRAD:
15409 {
15410 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15411 {
15412 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15413 }
15414 else combobuf[ri->combosref].liftlightrad = vbound(value/10000, 0, 255);
15415 break;
15416 }
15417 case COMBODLIFTLIGHTSHAPE:
15418 {
15419 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15420 {
15421 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15422 }
15423 else combobuf[ri->combosref].liftlightshape = vbound(value/10000, 0, 2);
15424 break;
15425 }
15426 case COMBODLIFTWEAPONITEM:
15427 {
15428 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15429 {
15430 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15431 }
15432 else combobuf[ri->combosref].lift_parent_item = vbound(value/10000, 0, 255);
15433 break;
15434 }
15435 case COMBODTRIGGERLSTATE:
15436 {
15437 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15438 {
15439 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15440 }
15441 else if(auto* trig = get_first_combo_trigger())
15442 trig->trig_lstate = vbound(value/10000, 0, 31);
15443 break;
15444 }
15445 case COMBODTRIGGERGSTATE:
15446 {
15447 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15448 {
15449 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15450 }
15451 else if(auto* trig = get_first_combo_trigger())
15452 trig->trig_gstate = vbound(value/10000, 0, 255);
15453 break;
15454 }
15455 case COMBODTRIGGERGROUP:
15456 {
15457 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15458 {
15459 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15460 }
15461 else if(auto* trig = get_first_combo_trigger())
15462 trig->trig_group = vbound(value/10000, 0, 255);
15463 break;
15464 }
15465 case COMBODTRIGGERGROUPVAL:
15466 {
15467 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15468 {
15469 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15470 }
15471 else if(auto* trig = get_first_combo_trigger())
15472 trig->trig_group_val = vbound(value/10000, 0, 65535);
15473 break;
15474 }
15475 case COMBODTRIGGERGTIMER:
15476 {
15477 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15478 {
15479 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15480 }
15481 else if(auto* trig = get_first_combo_trigger())
15482 trig->trig_statetime = vbound(value/10000, 0, 214748);
15483 break;
15484 }
15485 case COMBODTRIGGERGENSCRIPT:
15486 {
15487 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15488 {
15489 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15490 }
15491 else if(auto* trig = get_first_combo_trigger())
15492 trig->trig_genscr = vbound(value/10000, 0, 65535);
15493 break;
15494 }
15495 case COMBODTRIGGERLEVEL:
15496 {
15497 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15498 {
15499 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15500 }
15501 else if(auto* trig = get_first_combo_trigger())
15502 trig->triggerlevel = vbound(value/10000, 0, 214747);
15503 break;
15504 }
15505 case COMBODNUMTRIGGERS:
15506 {
15507 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15508 {
15509 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15510 }
15511 else
15512 combobuf[ri->combosref].triggers.resize(vbound(value / 10000, 0, MAX_COMBO_TRIGGERS));
15513 break;
15514 }
15515 case COMBODONLYGEN:
15516 {
15517 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
15518 {
15519 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
15520 }
15521 else
15522 combobuf[ri->combosref].only_gentrig = value != 0 ? 1 : 0;
15523 break;
15524 }
15525
15526
15527
15528
15529 //COMBOCLASS STRUCT
15530 //case COMBODNAME: //CHAR[64], STRING
15531 case COMBODBLOCKNPC: SET_COMBOCLASS_VAR_BYTE(block_enemies); break; //C
15532 case COMBODBLOCKHOLE: SET_COMBOCLASS_VAR_BYTE(block_hole); break; //C
15533 case COMBODBLOCKTRIG: SET_COMBOCLASS_VAR_BYTE(block_trigger); break; //C
15534 // Note: not used?
15535 case COMBODBLOCKWEAPON: SET_COMBOCLASS_BYTE_INDEX(block_weapon, 32); break; //C, 32 INDICES
15536 case COMBODCONVXSPEED: SET_COMBOCLASS_VAR_DWORD(conveyor_x_speed); break; //SHORT
15537 case COMBODCONVYSPEED: SET_COMBOCLASS_VAR_DWORD(conveyor_y_speed); break; //SHORT
15538 case COMBODSPAWNNPC: SET_COMBOCLASS_VAR_DWORD(create_enemy); break; //W
15539 case COMBODSPAWNNPCWHEN: SET_COMBOCLASS_VAR_BYTE(create_enemy_when); break; //C
15540 case COMBODSPAWNNPCCHANGE: SET_COMBOCLASS_VAR_INT(create_enemy_change); break; //LONG
15541 case COMBODDIRCHANGETYPE: SET_COMBOCLASS_VAR_BYTE(directional_change_type); break; //C
15542 case COMBODDISTANCECHANGETILES: SET_COMBOCLASS_VAR_INT(distance_change_tiles); break; //LONG
15543 case COMBODDIVEITEM: SET_COMBOCLASS_VAR_DWORD(dive_item); break; //SHORT
15544 case COMBODDOCK: SET_COMBOCLASS_VAR_BYTE(dock); break; //C
15545 case COMBODFAIRY: SET_COMBOCLASS_VAR_BYTE(fairy); break; //C
15546 case COMBODFFATTRCHANGE: SET_COMBOCLASS_VAR_BYTE(ff_combo_attr_change); break; //C
15547 case COMBODFOORDECOTILE: SET_COMBOCLASS_VAR_INT(foot_decorations_tile); break; //LONG
15548 case COMBODFOORDECOTYPE: SET_COMBOCLASS_VAR_BYTE(foot_decorations_type); break; //C
15549 case COMBODHOOKSHOTPOINT: SET_COMBOCLASS_VAR_BYTE(hookshot_grab_point); break; //C
15550 case COMBODLADDERPASS: SET_COMBOCLASS_VAR_BYTE(ladder_pass); break; //C
15551 case COMBODLOCKBLOCK: SET_COMBOCLASS_VAR_BYTE(lock_block_type); break; //C
15552 case COMBODLOCKBLOCKCHANGE: SET_COMBOCLASS_VAR_INT(lock_block_change); break; //LONG
15553 case COMBODMAGICMIRROR: SET_COMBOCLASS_VAR_BYTE(magic_mirror_type); break; //C
15554 case COMBODMODHPAMOUNT: SET_COMBOCLASS_VAR_DWORD(modify_hp_amount); break; //SHORT
15555 case COMBODMODHPDELAY: SET_COMBOCLASS_VAR_BYTE(modify_hp_delay); break; //C
15556 case COMBODMODHPTYPE: SET_COMBOCLASS_VAR_BYTE(modify_hp_type); break; //C
15557 case COMBODNMODMPAMOUNT: SET_COMBOCLASS_VAR_DWORD(modify_mp_amount); break; //SHORT
15558 case COMBODMODMPDELAY: SET_COMBOCLASS_VAR_BYTE(modify_mp_delay); break; //C
15559 case COMBODMODMPTYPE: SET_COMBOCLASS_VAR_BYTE(modify_mp_type); break; //C
15560 case COMBODNOPUSHBLOCK: SET_COMBOCLASS_VAR_BYTE(no_push_blocks); break; //C
15561 case COMBODOVERHEAD: SET_COMBOCLASS_VAR_BYTE(overhead); break; //C
15562 case COMBODPLACENPC: SET_COMBOCLASS_VAR_BYTE(place_enemy); break; //C
15563 case COMBODPUSHDIR: SET_COMBOCLASS_VAR_BYTE(push_direction); break; //C
15564 case COMBODPUSHWAIT: SET_COMBOCLASS_VAR_BYTE(push_wait); break; //C
15565 case COMBODPUSHHEAVY: SET_COMBOCLASS_VAR_BYTE(push_weight); break; //C
15566 case COMBODPUSHED: SET_COMBOCLASS_VAR_BYTE(pushed); break; //C
15567 case COMBODRAFT: SET_COMBOCLASS_VAR_BYTE(raft); break; //C
15568 case COMBODRESETROOM: SET_COMBOCLASS_VAR_BYTE(reset_room); break; //C
15569 case COMBODSAVEPOINTTYPE: SET_COMBOCLASS_VAR_BYTE(save_point_type); break; //C
15570 case COMBODSCREENFREEZETYPE: SET_COMBOCLASS_VAR_BYTE(screen_freeze_type); break; //C
15571 case COMBODSECRETCOMBO: SET_COMBOCLASS_VAR_BYTE(secret_combo); break; //C
15572 case COMBODSINGULAR: SET_COMBOCLASS_VAR_BYTE(singular); break; //C
15573 case COMBODSLOWWALK: SET_COMBOCLASS_VAR_BYTE(slow_movement); break; //C
15574 case COMBODSTATUETYPE: SET_COMBOCLASS_VAR_BYTE(statue_type); break; //C
15575 case COMBODSTEPTYPE: SET_COMBOCLASS_VAR_BYTE(step_type); break; //C
15576 case COMBODSTEPCHANGEINTO: SET_COMBOCLASS_VAR_INT(step_change_to); break; //LONG
15577 case COMBODSTRIKEWEAPONS: SET_COMBOCLASS_BYTE_INDEX(strike_weapons, 32); break; //BYTE, 32 INDICES.
15578 case COMBODSTRIKEREMNANTS: SET_COMBOCLASS_VAR_INT(strike_remnants); break; //LONG
15579 case COMBODSTRIKEREMNANTSTYPE: SET_COMBOCLASS_VAR_BYTE(strike_remnants_type); break; //C
15580 case COMBODSTRIKECHANGE: SET_COMBOCLASS_VAR_INT(strike_change); break; //LONG
15581 case COMBODSTRIKEITEM: SET_COMBOCLASS_VAR_DWORD(strike_item); break; //SHORT
15582 case COMBODTOUCHITEM: SET_COMBOCLASS_VAR_DWORD(touch_item); break; //SHORT
15583 case COMBODTOUCHSTAIRS: SET_COMBOCLASS_VAR_BYTE(touch_stairs); break; //C
15584 case COMBODTRIGGERTYPE: SET_COMBOCLASS_VAR_BYTE(trigger_type); break; //C
15585 case COMBODTRIGGERSENS: SET_COMBOCLASS_VAR_BYTE(trigger_sensitive); break; //C
15586 case COMBODWARPTYPE: SET_COMBOCLASS_VAR_BYTE(warp_type); break; //C
15587 case COMBODWARPSENS: SET_COMBOCLASS_VAR_BYTE(warp_sensitive); break; //C
15588 case COMBODWARPDIRECT: SET_COMBOCLASS_VAR_BYTE(warp_direct); break; //C
15589 case COMBODWARPLOCATION: SET_COMBOCLASS_VAR_BYTE(warp_location); break; //C
15590 case COMBODWATER: SET_COMBOCLASS_VAR_BYTE(water); break; //C
15591 case COMBODWHISTLE: SET_COMBOCLASS_VAR_BYTE(whistle); break; //C
15592 case COMBODWINGAME: SET_COMBOCLASS_VAR_BYTE(win_game); break; //C
15593 case COMBODBLOCKWPNLEVEL: SET_COMBOCLASS_VAR_BYTE(block_weapon_lvl); break; //C
15594
15595
15596
15597 ///----------------------------------------------------------------------------------------------------//
15598 case CMBTRIGWPNLEVEL:
15599 {
15600 if(auto* trig = get_combo_trigger(ri->combotrigref))
15601 {
15602 trig->triggerlevel = vbound(value/10000, 0, 214748);
15603 }
15604 break;
15605 }
15606 case CMBTRIGREQITEM:
15607 {
15608 if(auto* trig = get_combo_trigger(ri->combotrigref))
15609 {
15610 trig->triggeritem = vbound(value/10000, 0, MAXITEMS-1);
15611 }
15612 break;
15613 }
15614 case CMBTRIGTIMER:
15615 {
15616 if(auto* trig = get_combo_trigger(ri->combotrigref))
15617 {
15618 trig->trigtimer = vbound(value/10000, 0, 65535);
15619 }
15620 break;
15621 }
15622 case CMBTRIGSFX:
15623 {
15624 if(auto* trig = get_combo_trigger(ri->combotrigref))
15625 {
15626 trig->trigsfx = vbound(value/10000, 0, 255);
15627 }
15628 break;
15629 }
15630 case CMBTRIGCHANGECMB:
15631 {
15632 if(auto* trig = get_combo_trigger(ri->combotrigref))
15633 {
15634 trig->trigchange = value/10000;
15635 }
15636 break;
15637 }
15638 case CMBTRIGCSETCHANGE:
15639 {
15640 if(auto* trig = get_combo_trigger(ri->combotrigref))
15641 {
15642 trig->trigcschange = vbound(value/10000, -128, 127);
15643 }
15644 break;
15645 }
15646 case CMBTRIGPROX:
15647 {
15648 if(auto* trig = get_combo_trigger(ri->combotrigref))
15649 {
15650 trig->trigprox = vbound(value/10000, 0, 65535);
15651 }
15652 break;
15653 }
15654 case CMBTRIGLIGHTBEAM:
15655 {
15656 if(auto* trig = get_combo_trigger(ri->combotrigref))
15657 {
15658 trig->triglbeam = vbound(value/10000,0,32);
15659 }
15660 break;
15661 }
15662 case CMBTRIGCTR:
15663 {
15664 if(auto* trig = get_combo_trigger(ri->combotrigref))
15665 {
15666 trig->trigctr = vbound(value/10000, sscMIN, MAX_COUNTERS-1);
15667 }
15668 break;
15669 }
15670 case CMBTRIGCTRAMNT:
15671 {
15672 if(auto* trig = get_combo_trigger(ri->combotrigref))
15673 {
15674 trig->trigctramnt = vbound(value/10000, -65535, 65535);
15675 }
15676 break;
15677 }
15678 case CMBTRIGCOOLDOWN:
15679 {
15680 if(auto* trig = get_combo_trigger(ri->combotrigref))
15681 {
15682 trig->trigcooldown = vbound(value/10000, 0, 255);
15683 }
15684 break;
15685 }
15686 case CMBTRIGCOPYCAT:
15687 {
15688 if(auto* trig = get_combo_trigger(ri->combotrigref))
15689 {
15690 trig->trigcopycat = vbound(value/10000, 0, 255);
15691 }
15692 break;
15693 }
15694 case CMBTRIGITEMPICKUP:
15695 {
15696 const int32_t allowed_pflags = ipHOLDUP | ipTIMER | ipSECRETS | ipCANGRAB;
15697 if(auto* trig = get_combo_trigger(ri->combotrigref))
15698 {
15699 trig->spawnip = (value/10000)&allowed_pflags;
15700 }
15701 break;
15702 }
15703 case CMBTRIGEXSTATE:
15704 {
15705 if(auto* trig = get_combo_trigger(ri->combotrigref))
15706 {
15707 trig->exstate = vbound(value/10000, -1, 31);
15708 }
15709 break;
15710 }
15711 case CMBTRIGEXDOORDIR:
15712 {
15713 if(auto* trig = get_combo_trigger(ri->combotrigref))
15714 {
15715 trig->exdoor_dir = vbound(value/10000, -1, 3);
15716 }
15717 break;
15718 }
15719 case CMBTRIGEXDOORIND:
15720 {
15721 if(auto* trig = get_combo_trigger(ri->combotrigref))
15722 {
15723 trig->exdoor_ind = vbound(value/10000, 0, 7);
15724 }
15725 break;
15726 }
15727 case CMBTRIGSPAWNENEMY:
15728 {
15729 if(auto* trig = get_combo_trigger(ri->combotrigref))
15730 {
15731 trig->spawnenemy = vbound(value/10000, 0, 511);
15732 }
15733 break;
15734 }
15735 case CMBTRIGSPAWNITEM:
15736 {
15737 if(auto* trig = get_combo_trigger(ri->combotrigref))
15738 {
15739 trig->spawnitem = vbound(value/10000, -255, 255);
15740 }
15741 break;
15742 }
15743 case CMBTRIGLSTATE:
15744 {
15745 if(auto* trig = get_combo_trigger(ri->combotrigref))
15746 {
15747 trig->trig_lstate = vbound(value/10000, 0, 31);
15748 }
15749 break;
15750 }
15751 case CMBTRIGGSTATE:
15752 {
15753 if(auto* trig = get_combo_trigger(ri->combotrigref))
15754 {
15755 trig->trig_gstate = vbound(value/10000, 0, 255);
15756 }
15757 break;
15758 }
15759 case CMBTRIGGTIMER:
15760 {
15761 if(auto* trig = get_combo_trigger(ri->combotrigref))
15762 {
15763 trig->trig_statetime = vbound(value/10000, 0, 214748);
15764 }
15765 break;
15766 }
15767 case CMBTRIGGENSCRIPT:
15768 {
15769 if(auto* trig = get_combo_trigger(ri->combotrigref))
15770 {
15771 trig->trig_genscr = vbound(value/10000, 0, 65535);
15772 }
15773 break;
15774 }
15775 case CMBTRIGGROUP:
15776 {
15777 if(auto* trig = get_combo_trigger(ri->combotrigref))
15778 {
15779 trig->trig_group = vbound(value/10000, 0, 255);
15780 }
15781 break;
15782 }
15783 case CMBTRIGGROUPVAL:
15784 {
15785 if(auto* trig = get_combo_trigger(ri->combotrigref))
15786 {
15787 trig->trig_group_val = vbound(value/10000, 0, 65535);
15788 }
15789 break;
15790 }
15791 case CMBTRIGLITEMS:
15792 {
15793 if(auto* trig = get_combo_trigger(ri->combotrigref))
15794 {
15795 trig->trig_levelitems = (value/10000) & liALL;
15796 }
15797 break;
15798 }
15799 case CMBTRIGDMAPLVL:
15800 {
15801 if(auto* trig = get_combo_trigger(ri->combotrigref))
15802 {
15803 trig->trigdmlevel = vbound(value/10000, -1, MAXLEVELS-1);
15804 }
15805 break;
15806 }
15807 case CMBTRIGTINTR:
15808 {
15809 if(auto* trig = get_combo_trigger(ri->combotrigref))
15810 {
15811 trig->trigtint[0] = scripting_write_pal_color(vbound(value/10000, -scripting_max_color_val, scripting_max_color_val));
15812 }
15813 break;
15814 }
15815 case CMBTRIGTINTG:
15816 {
15817 if(auto* trig = get_combo_trigger(ri->combotrigref))
15818 {
15819 trig->trigtint[1] = scripting_write_pal_color(vbound(value/10000, -scripting_max_color_val, scripting_max_color_val));
15820 }
15821 break;
15822 }
15823 case CMBTRIGTINTB:
15824 {
15825 if(auto* trig = get_combo_trigger(ri->combotrigref))
15826 {
15827 trig->trigtint[2] = scripting_write_pal_color(vbound(value/10000, -scripting_max_color_val, scripting_max_color_val));
15828 }
15829 break;
15830 }
15831 case CMBTRIGLVLPAL:
15832 {
15833 if(auto* trig = get_combo_trigger(ri->combotrigref))
15834 {
15835 trig->triglvlpalette = vbound(value/10000, -1, 512);
15836 }
15837 break;
15838 }
15839 case CMBTRIGBOSSPAL:
15840 {
15841 if(auto* trig = get_combo_trigger(ri->combotrigref))
15842 {
15843 trig->trigbosspalette = vbound(value/10000, -1, 29);
15844 }
15845 break;
15846 }
15847 case CMBTRIGQUAKETIME:
15848 {
15849 if(auto* trig = get_combo_trigger(ri->combotrigref))
15850 {
15851 trig->trigquaketime = zc_max(value/10000, -1);
15852 }
15853 break;
15854 }
15855 case CMBTRIGWAVYTIME:
15856 {
15857 if(auto* trig = get_combo_trigger(ri->combotrigref))
15858 {
15859 trig->trigwavytime = zc_max(value/10000, -1);
15860 }
15861 break;
15862 }
15863 case CMBTRIGSWORDJINX:
15864 {
15865 if(auto* trig = get_combo_trigger(ri->combotrigref))
15866 {
15867 trig->trig_swjinxtime = zc_max(value/10000, -2);
15868 }
15869 break;
15870 }
15871 case CMBTRIGITEMJINX:
15872 {
15873 if(auto* trig = get_combo_trigger(ri->combotrigref))
15874 {
15875 trig->trig_itmjinxtime = zc_max(value/10000, -2);
15876 }
15877 break;
15878 }
15879 case CMBTRIGSHIELDJINX:
15880 {
15881 if(auto* trig = get_combo_trigger(ri->combotrigref))
15882 {
15883 trig->trig_shieldjinxtime = zc_max(value/10000, -2);
15884 }
15885 break;
15886 }
15887 case CMBTRIGSTUN:
15888 {
15889 if(auto* trig = get_combo_trigger(ri->combotrigref))
15890 {
15891 trig->trig_stuntime = zc_max(value/10000, -2);
15892 }
15893 break;
15894 }
15895 case CMBTRIGBUNNY:
15896 {
15897 if(auto* trig = get_combo_trigger(ri->combotrigref))
15898 {
15899 trig->trig_bunnytime = zc_max(value/10000, -2);
15900 }
15901 break;
15902 }
15903 case CMBTRIGPUSHTIME:
15904 {
15905 if(auto* trig = get_combo_trigger(ri->combotrigref))
15906 {
15907 trig->trig_pushtime = vbound(value/10000, 0, 255);
15908 }
15909 break;
15910 }
15911 case CMBTRIGGERPROMPTCID:
15912 {
15913 if(auto* trig = get_combo_trigger(ri->combotrigref))
15914 trig->prompt_cid = vbound(value/10000, 0, MAXCOMBOS-1);
15915 break;
15916 }
15917 case CMBTRIGGERPROMPTCS:
15918 {
15919 if(auto* trig = get_combo_trigger(ri->combotrigref))
15920 trig->prompt_cs = (value/10000)&15;
15921 break;
15922 }
15923 case CMBTRIGGERFAILPROMPTCID:
15924 {
15925 if(auto* trig = get_combo_trigger(ri->combotrigref))
15926 trig->fail_prompt_cid = vbound(value/10000, 0, MAXCOMBOS-1);
15927 break;
15928 }
15929 case CMBTRIGGERFAILPROMPTCS:
15930 {
15931 if(auto* trig = get_combo_trigger(ri->combotrigref))
15932 trig->fail_prompt_cs = (value/10000)&15;
15933 break;
15934 }
15935 case CMBTRIGGERPROMPTX:
15936 {
15937 if(auto* trig = get_combo_trigger(ri->combotrigref))
15938 trig->prompt_x = vbound(value/10000, -32768, 32767);
15939 break;
15940 }
15941 case CMBTRIGGERPROMPTY:
15942 {
15943 if(auto* trig = get_combo_trigger(ri->combotrigref))
15944 trig->prompt_y = vbound(value/10000, -32768, 32767);
15945 break;
15946 }
15947 case CMBTRIGGERTRIGSTR:
15948 {
15949 if(auto* trig = get_combo_trigger(ri->combotrigref))
15950 trig->trig_msgstr = vbound(value/10000, 0, msg_count-1);
15951 break;
15952 }
15953 case CMBTRIGGERFAILSTR:
15954 {
15955 if(auto* trig = get_combo_trigger(ri->combotrigref))
15956 trig->fail_msgstr = vbound(value/10000, 0, msg_count-1);
15957 break;
15958 }
15959 case CMBTRIGGERPLAYERBOUNCE:
15960 {
15961 if(auto* trig = get_combo_trigger(ri->combotrigref))
15962 trig->player_bounce = value;
15963 break;
15964 }
15965 case CMBTRIGGERREQPLAYERZ:
15966 {
15967 if(auto* trig = get_combo_trigger(ri->combotrigref))
15968 trig->req_player_z = value;
15969 break;
15970 }
15971 case CMBTRIGGERDESTHEROX:
15972 {
15973 if(auto* trig = get_combo_trigger(ri->combotrigref))
15974 trig->dest_player_x = value;
15975 break;
15976 }
15977 case CMBTRIGGERDESTHEROY:
15978 {
15979 if(auto* trig = get_combo_trigger(ri->combotrigref))
15980 trig->dest_player_y = value;
15981 break;
15982 }
15983 case CMBTRIGGERDESTHEROZ:
15984 {
15985 if(auto* trig = get_combo_trigger(ri->combotrigref))
15986 trig->dest_player_z = value;
15987 break;
15988 }
15989 case CMBTRIGGERREQPLAYERJUMP:
15990 {
15991 if(auto* trig = get_combo_trigger(ri->combotrigref))
15992 trig->req_player_jump = value;
15993 break;
15994 }
15995 case CMBTRIGGERREQPLAYERX:
15996 {
15997 if(auto* trig = get_combo_trigger(ri->combotrigref))
15998 trig->req_player_x = value;
15999 break;
16000 }
16001 case CMBTRIGGERREQPLAYERY:
16002 {
16003 if(auto* trig = get_combo_trigger(ri->combotrigref))
16004 trig->req_player_y = value;
16005 break;
16006 }
16007 ///----------------------------------------------------------------------------------------------------//
16008 //npcdata nd-> Variables
16009
16010 #define SET_NPCDATA_VAR_INT(member, str) \
16011 { \
16012 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
16013 { \
16014 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", (ri->npcdataref*10000), str); \
16015 } \
16016 else \
16017 { \
16018 guysbuf[ri->npcdataref].member = vbound((value / 10000),0,214747); \
16019 } \
16020 } \
16021
16022 #define SET_NPCDATA_VAR_DWORD(member, str) \
16023 { \
16024 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
16025 { \
16026 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", (ri->npcdataref*10000), str); \
16027 } \
16028 else \
16029 { \
16030 guysbuf[ri->npcdataref].member = vbound((value / 10000),0,32767); \
16031 } \
16032 } \
16033
16034 #define SET_NPCDATA_VAR_ENUM(member, str) \
16035 { \
16036 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
16037 { \
16038 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", (ri->npcdataref*10000), str); \
16039 } \
16040 else \
16041 { \
16042 guysbuf[ri->npcdataref].member = (decltype(guysbuf[ri->npcdataref].member))vbound((value / 10000),0,32767); \
16043 } \
16044 } \
16045
16046 #define SET_NPCDATA_VAR_BYTE(member, str) \
16047 { \
16048 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
16049 { \
16050 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", (ri->npcdataref*10000), str); \
16051 } \
16052 else \
16053 { \
16054 guysbuf[ri->npcdataref].member = vbound((value / 10000),0,255); \
16055 } \
16056 } \
16057
16058 #define SET_NPCDATA_FLAG(member, str) \
16059 { \
16060 int32_t flag = (value/10000); \
16061 if( (unsigned) ri->npcdataref > (MAXNPCS-1) ) \
16062 { \
16063 Z_scripterrlog("Invalid NPC ID passed to npcdata->%s: %d\n", (ri->npcdataref*10000), str); \
16064 } \
16065 else \
16066 { \
16067 if ( flag ) \
16068 { \
16069 guysbuf[ri->npcdataref].member|=flag; \
16070 } \
16071 else guysbuf[ri->npcdataref].member|= ~flag; \
16072 } \
16073 } \
16074
16075 case NPCDATATILE: SET_NPCDATA_VAR_BYTE(tile, "Tile"); break;
16076 case NPCDATAWIDTH: SET_NPCDATA_VAR_BYTE(width, "Width"); break;
16077 case NPCDATAHEIGHT: SET_NPCDATA_VAR_BYTE(height, "Height"); break;
16078 case NPCDATAFLAGS1: SET_NPCDATA_VAR_ENUM(flags, "Flags (deprecated)"); break;
16079 case NPCDATAFLAGS2: SET_NPCDATA_VAR_ENUM(flags, "Flags2 (deprecated)"); break;
16080 case NPCDATASTILE: SET_NPCDATA_VAR_BYTE(s_tile, "STile"); break;
16081 case NPCDATASWIDTH: SET_NPCDATA_VAR_BYTE(s_width, "SWidth"); break;
16082 case NPCDATASHEIGHT: SET_NPCDATA_VAR_BYTE(s_height, "SHeight"); break;
16083 case NPCDATAETILE: SET_NPCDATA_VAR_INT(e_tile, "ExTile"); break;
16084 case NPCDATAEWIDTH: SET_NPCDATA_VAR_BYTE(e_width, "ExWidth"); break;
16085 case NPCDATASCRIPT: SET_NPCDATA_VAR_BYTE(script, "Script"); break;
16086 case NPCDATAEHEIGHT: SET_NPCDATA_VAR_BYTE(e_height, "ExHeight"); break;
16087 case NPCDATAHP: SET_NPCDATA_VAR_DWORD(hp, "HP"); break;
16088 case NPCDATAFAMILY: SET_NPCDATA_VAR_DWORD(family, "Family"); break;
16089 case NPCDATACSET: SET_NPCDATA_VAR_DWORD(cset, "CSet"); break;
16090 case NPCDATAANIM: SET_NPCDATA_VAR_DWORD(anim, "Anim"); break;
16091 case NPCDATAEANIM: SET_NPCDATA_VAR_DWORD(e_anim, "ExAnim"); break;
16092 case NPCDATAFRAMERATE: SET_NPCDATA_VAR_DWORD(frate, "Framerate"); break;
16093 case NPCDATAEFRAMERATE: SET_NPCDATA_VAR_DWORD(e_frate, "ExFramerate"); break;
16094 case NPCDATATOUCHDAMAGE: SET_NPCDATA_VAR_DWORD(dp, "TouchDamage"); break;
16095 case NPCDATAWEAPONDAMAGE: SET_NPCDATA_VAR_DWORD(wdp, "WeaponDamage"); break;
16096 case NPCDATAWEAPON: SET_NPCDATA_VAR_DWORD(weapon, "Weapon"); break;
16097 case NPCDATARANDOM: SET_NPCDATA_VAR_DWORD(rate, "Random"); break;
16098 case NPCDATAHALT: SET_NPCDATA_VAR_DWORD(hrate, "Haltrate"); break;
16099 case NPCDATASTEP: SET_NPCDATA_VAR_DWORD(step, "Step"); break;
16100 case NPCDATAHOMING: SET_NPCDATA_VAR_DWORD(homing, "Homing"); break;
16101 case NPCDATAHUNGER: SET_NPCDATA_VAR_DWORD(grumble, "Hunger"); break;
16102 case NPCDATADROPSET: SET_NPCDATA_VAR_DWORD(item_set, "Dropset"); break;
16103 case NPCDATABGSFX: SET_NPCDATA_VAR_DWORD(bgsfx, "BGSFX"); break;
16104 case NPCDATADEATHSFX: SET_NPCDATA_VAR_BYTE(deadsfx, "DeathSFX"); break;
16105 case NPCDATAHITSFX: SET_NPCDATA_VAR_BYTE(hitsfx, "HitSFX"); break;
16106 case NPCDATAXOFS: SET_NPCDATA_VAR_INT(xofs, "DrawXOffset"); break;
16107 case NPCDATAYOFS: SET_NPCDATA_VAR_INT(yofs, "DrawYOffset"); break;
16108 case NPCDATAZOFS: SET_NPCDATA_VAR_INT(zofs, "DrawZOffset"); break;
16109 case NPCDATAHXOFS: SET_NPCDATA_VAR_INT(hxofs, "HitXOffset"); break;
16110 case NPCDATAHYOFS: SET_NPCDATA_VAR_INT(hyofs, "HitYOffset"); break;
16111 case NPCDATAHITWIDTH: SET_NPCDATA_VAR_INT(hxsz, "HitWidth"); break;
16112 case NPCDATAHITHEIGHT: SET_NPCDATA_VAR_INT(hysz, "HitHeight"); break;
16113 case NPCDATAHITZ: SET_NPCDATA_VAR_INT(hzsz, "HitZHeight"); break;
16114 case NPCDATATILEWIDTH: SET_NPCDATA_VAR_INT(txsz, "TileWidth"); break;
16115 case NPCDATATILEHEIGHT: SET_NPCDATA_VAR_INT(tysz, "TileHeight"); break;
16116 case NPCDATAWPNSPRITE: SET_NPCDATA_VAR_INT(wpnsprite, "WeaponSprite"); break;
16117 case NPCDATAWEAPONSCRIPT: SET_NPCDATA_VAR_INT(weaponscript, "WeaponScript"); break;
16118 case NPCDATASIZEFLAG: SET_NPCDATA_VAR_INT(SIZEflags, "SizeFlags"); break;
16119
16120 case NPCDATAFROZENTILE: SET_NPCDATA_VAR_INT(frozentile, "FrozenTile"); break;
16121 case NPCDATAFROZENCSET: SET_NPCDATA_VAR_INT(frozencset, "FrozenCSet"); break;
16122 case NPCDATAFIRESFX: SET_NPCDATA_VAR_BYTE(firesfx, "WeaponSFX"); break;
16123
16124 case NPCDSHADOWSPR:
16125 {
16126 if(ri->npcdataref > (MAXNPCS-1) )
16127 {
16128 Z_scripterrlog("Invalid NPC ID passed to npcdata->ShadowSprite: %d\n", (ri->npcdataref*10000));
16129 }
16130 else
16131 {
16132 guysbuf[ri->npcdataref].spr_shadow = vbound(value/10000, 0, 255);
16133 }
16134 break;
16135 }
16136 case NPCDSPAWNSPR:
16137 {
16138 if(ri->npcdataref > (MAXNPCS-1) )
16139 {
16140 Z_scripterrlog("Invalid NPC ID passed to npcdata->SpawnSprite: %d\n", (ri->npcdataref*10000));
16141 }
16142 else
16143 {
16144 guysbuf[ri->npcdataref].spr_spawn = vbound(value/10000, 0, 255);
16145 }
16146 break;
16147 }
16148 case NPCDDEATHSPR:
16149 {
16150 if(ri->npcdataref > (MAXNPCS-1) )
16151 {
16152 Z_scripterrlog("Invalid NPC ID passed to npcdata->DeathSprite: %d\n", (ri->npcdataref*10000));
16153 }
16154 else
16155 {
16156 guysbuf[ri->npcdataref].spr_death = vbound(value/10000, 0, 255);
16157 }
16158 break;
16159 }
16160
16161
16162 ///----------------------------------------------------------------------------------------------------//
16163 //Dropset Variables
16164
16165 case DROPSETNULLCHANCE:
16166 {
16167 if(ri->dropsetref > MAXITEMDROPSETS)
16168 {
16169 Z_scripterrlog("Invalid dropset pointer %d\n", ri->dropsetref);
16170 break;
16171 }
16172 item_drop_sets[ri->dropsetref].chance[0] = vbound((value / 10000),0,32767);
16173 break;
16174 }
16175
16176 ///----------------------------------------------------------------------------------------------------//
16177 //Audio Variables
16178
16179 case AUDIOPAN:
16180 {
16181 if ( !(FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE) )
16182 {
16183 FFCore.usr_panstyle = FFScript::do_getSFX_pan();
16184 FFCore.SetFFEngineFlag(FFCORE_SCRIPTED_PANSTYLE,true);
16185 }
16186 FFScript::do_setSFX_pan(value/10000);
16187 break;
16188 }
16189
16190 ///----------------------------------------------------------------------------------------------------//
16191 //Graphics->
16192
16193 case NUMDRAWS:
16194 break;
16195
16196 case MAXDRAWS: break;
16197
16198 ///----------------------------------------------------------------------------------------------------//
16199 //Misc./Internal
16200 case SP:
16201 ri->sp = value / 10000;
16202 ri->sp &= MASK_SP;
16203 break;
16204
16205 case SP2:
16206 ri->sp = value;
16207 ri->sp &= MASK_SP;
16208 break;
16209
16210 case PC:
16211 ri->pc = value;
16212 break;
16213
16214 case SWITCHKEY:
16215 4 ri->switchkey = value;
16216 4 break;
16217
16218 case SCRIPTRAM:
16219 case GLOBALRAM:
16220 531793827 ArrayH::setElement(ri->d[rINDEX], ri->d[rINDEX2] / 10000, value);
16221 531793827 break;
16222
16223 case SCRIPTRAMD:
16224 case GLOBALRAMD:
16225 ArrayH::setElement(ri->d[rINDEX], 0, value);
16226 break;
16227
16228 case REFFFC:
16229
2/2
✓ Branch 0 taken 6374648 times.
✓ Branch 1 taken 639949442 times.
646324090 ri->ffcref = ZScriptVersion::ffcRefIsSpriteId() ? value : value / 10000;
16230 646324090 break;
16231
16232 case REFITEM:
16233 2239361 ri->itemref = value;
16234 2239361 break;
16235
16236 case REFITEMCLASS:
16237 6367264 ri->idata = value;
16238 6367264 break;
16239
16240 case REFLWPN:
16241 12117383 ri->lwpn = value;
16242 12117383 break;
16243
16244 case REFEWPN:
16245 46788128 ri->ewpn = value;
16246 46788128 break;
16247
16248 case REFNPC:
16249 162664402 ri->guyref = value;
16250 162664402 break;
16251
16252 case REFSPRITE:
16253 43220079 ri->spriteref = value;
16254 43220079 break;
16255
16256 88305847 case REFMAPDATA: ri->mapsref = value; break;
16257 case REFSCREENDATA: ri->screenref = value; break;
16258 838813 case REFCOMBODATA: ri->combosref = value; break;
16259 case REFCOMBOTRIGGER: ri->combotrigref = value; break;
16260 64 case REFSPRITEDATA: ri->spritedataref = value; break;
16261 410111 case REFBITMAP: ri->bitmapref = value; break;
16262 1 case REFNPCCLASS: ri->npcdataref = value; break;
16263
16264 77218 case REFDMAPDATA: ri->dmapsref = value; break;
16265 case REFSHOPDATA: ri->shopsref = value; break;
16266 124 case REFMSGDATA: ri->zmsgref = value; break;
16267
16268
16269 10 case REFDROPS: ri->dropsetref = value; break;
16270 case REFBOTTLETYPE: ri->bottletyperef = value; break;
16271 case REFBOTTLESHOP: ri->bottleshopref = value; break;
16272 8474693 case REFGENERICDATA: ri->genericdataref = value; break;
16273 284 case REFFILE: ri->fileref = value; break;
16274 case REFDIRECTORY: ri->directoryref = value; break;
16275 case REFSTACK: ri->stackref = value; break;
16276 109743 case REFSUBSCREEN: ri->subdataref = value; break;
16277 20806 case REFSUBSCREENPAGE: ri->subpageref = value; break;
16278 103742 case REFSUBSCREENWIDG: ri->subwidgref = value; break;
16279 449481 case REFRNG: ri->rngref = value; break;
16280 case REFWEBSOCKET: ri->websocketref = value; break;
16281 3373 case CLASS_THISKEY: ri->thiskey = value; break;
16282 1113 case CLASS_THISKEY2: ri->thiskey2 = value; break;
16283 7263 case REFPALDATA: ri->paldataref = value; break;
16284
16285 //-------------------------------------------------------------------------------------------------
16286
16287 case GENDATARUNNING:
16288 {
16289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 115 times.
115 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
16290 {
16291
1/2
✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
115 if(value)
16292 115 scr->launch();
16293 else scr->quit();
16294 115 }
16295 115 break;
16296 }
16297 case GENDATASIZE:
16298 {
16299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
38 if(user_genscript* scr = checkGenericScr(ri->genericdataref))
16300 {
16301 38 scr->dataResize(value/10000);
16302 38 }
16303 38 break;
16304 }
16305
16306 //----------------------------------------------------------------------------------------------------//
16307
16308 case PORTALX:
16309 {
16310 if(portal* p = checkPortal(ri->portalref))
16311 p->x = zslongToFix(value);
16312 break;
16313 }
16314 case PORTALY:
16315 {
16316 if(portal* p = checkPortal(ri->portalref))
16317 p->y = zslongToFix(value);
16318 break;
16319 }
16320 case PORTALDMAP:
16321 {
16322 if(portal* p = checkPortal(ri->portalref))
16323 p->destdmap = vbound(value/10000,-1,MAXDMAPS-1);
16324 break;
16325 }
16326 case PORTALSCREEN:
16327 {
16328 if(portal* p = checkPortal(ri->portalref))
16329 p->destscr = vbound(value/10000,0,255);
16330 break;
16331 }
16332 case PORTALACLK:
16333 {
16334 if(portal* p = checkPortal(ri->portalref))
16335 p->aclk = vbound(value/10000, 0, 9999);
16336 break;
16337 }
16338 case PORTALAFRM:
16339 {
16340 if(portal* p = checkPortal(ri->portalref))
16341 p->aframe = vbound(value/10000, 0, 9999);
16342 break;
16343 }
16344 case PORTALOTILE:
16345 {
16346 if(portal* p = checkPortal(ri->portalref))
16347 p->o_tile = vbound(value/10000, 0, NEWMAXTILES-1);
16348 break;
16349 }
16350 case PORTALASPD:
16351 {
16352 if(portal* p = checkPortal(ri->portalref))
16353 p->aspd = vbound(value/10000, 0, 9999);
16354 break;
16355 }
16356 case PORTALFRAMES:
16357 {
16358 if(portal* p = checkPortal(ri->portalref))
16359 p->frames = vbound(value/10000, 0, 9999);
16360 break;
16361 }
16362 case PORTALSAVED:
16363 {
16364 if(ri->portalref < 0 || value < 0) break;
16365 if(portal* p = checkPortal(ri->portalref))
16366 {
16367 if(!value)
16368 p->saved_data = 0;
16369 else if(savedportal* sp = checkSavedPortal(value))
16370 p->saved_data = sp->getUID();
16371 }
16372 break;
16373 }
16374 case PORTALCLOSEDIS:
16375 {
16376 if(portal* p = checkPortal(ri->portalref))
16377 p->prox_active = value==0; //Inverted
16378 break;
16379 }
16380 case REFPORTAL:
16381 {
16382 ri->portalref = value;
16383 break;
16384 }
16385 case REFSAVPORTAL:
16386 {
16387 ri->saveportalref = value;
16388 break;
16389 }
16390 case PORTALWARPSFX:
16391 {
16392 if(portal* p = checkPortal(ri->portalref))
16393 p->wsfx = vbound(value/10000,0,255);
16394 break;
16395 }
16396 case PORTALWARPVFX:
16397 {
16398 if(portal* p = checkPortal(ri->portalref))
16399 p->weffect = vbound(value/10000,0,255);
16400 break;
16401 }
16402 case SAVEDPORTALX:
16403 {
16404 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16405 p->x = value;
16406 break;
16407 }
16408 case SAVEDPORTALY:
16409 {
16410 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16411 p->y = value;
16412 break;
16413 }
16414 case SAVEDPORTALSRCDMAP:
16415 {
16416 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16417 p->srcdmap = vbound(value/10000, -1, MAXDMAPS-1);
16418 break;
16419 }
16420 case SAVEDPORTALDESTDMAP:
16421 {
16422 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16423 p->destdmap = vbound(value/10000, -1, MAXDMAPS-1);
16424 break;
16425 }
16426 case SAVEDPORTALSRCSCREEN:
16427 {
16428 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16429 p->srcscr = vbound(value/10000,0,255);
16430 break;
16431 }
16432 case SAVEDPORTALDSTSCREEN:
16433 {
16434 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16435 p->destscr = vbound(value/10000,0,255);
16436 break;
16437 }
16438 case SAVEDPORTALWARPSFX:
16439 {
16440 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16441 p->sfx = vbound(value/10000,0,255);
16442 break;
16443 }
16444 case SAVEDPORTALWARPVFX:
16445 {
16446 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16447 p->warpfx = vbound(value/10000,0,255);
16448 break;
16449 }
16450 case SAVEDPORTALSPRITE:
16451 {
16452 if(savedportal* p = checkSavedPortal(ri->saveportalref))
16453 p->spr = vbound(value/10000,0,255);
16454 break;
16455 }
16456 case SAVEDPORTALPORTAL:
16457 {
16458 if(ri->saveportalref < 0 || value < 0) break;
16459 if(savedportal* sp = checkSavedPortal(ri->saveportalref))
16460 {
16461 int32_t id = getPortalFromSaved(sp);
16462 if(id == value) break; //no change
16463 portal* p = checkPortal(value);
16464 if(p)
16465 {
16466 p->saved_data = sp->getUID();
16467 if(id > 0)
16468 {
16469 portal* p = checkPortal(id);
16470 p->saved_data = 0;
16471 }
16472 }
16473 }
16474 break;
16475 }
16476
16477 case GAMENUMASUB:
16478 {
16479 if(value >= 0)
16480 {
16481 size_t sz = vbound(value/10000, 0, 256);
16482 while(subscreens_active.size() < sz)
16483 {
16484 auto& sub = subscreens_active.emplace_back();
16485 sub.sub_type = sstACTIVE;
16486 }
16487 while(subscreens_active.size() > sz)
16488 subscreens_active.pop_back();
16489 }
16490 break;
16491 }
16492 case GAMENUMPSUB:
16493 {
16494 if(value >= 0)
16495 {
16496 size_t sz = vbound(value/10000, 0, 256);
16497 while(subscreens_passive.size() < sz)
16498 {
16499 auto& sub = subscreens_passive.emplace_back();
16500 sub.sub_type = sstPASSIVE;
16501 }
16502 while(subscreens_passive.size() > sz)
16503 subscreens_passive.pop_back();
16504 }
16505 break;
16506 }
16507 case GAMENUMOSUB:
16508 {
16509 if(value >= 0)
16510 {
16511 size_t sz = vbound(value/10000, 0, 256);
16512 while(subscreens_overlay.size() < sz)
16513 {
16514 auto& sub = subscreens_overlay.emplace_back();
16515 sub.sub_type = sstOVERLAY;
16516 }
16517 while(subscreens_overlay.size() > sz)
16518 subscreens_overlay.pop_back();
16519 }
16520 break;
16521 }
16522 ///----------------------------------------------------------------------------------------------------//
16523
16524 case SUBDATACURPG:
16525 {
16526
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
16527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
6 if(sub->sub_type == sstACTIVE)
16528 3 sub->curpage = vbound(value/10000,0,sub->pages.size()-1);
16529 3 break;
16530 }
16531 case SUBDATANUMPG:
16532 {
16533 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
16534 if(sub->sub_type == sstACTIVE && value >= 10000)
16535 {
16536 size_t sz = value/10000;
16537 while(sub->pages.size() < sz)
16538 if(!sub->add_page(MAX_SUBSCR_PAGES))
16539 break;
16540 while(sub->pages.size() > sz)
16541 sub->delete_page(sub->pages.size()-1);
16542 }
16543 break;
16544 }
16545 case SUBDATATYPE: break; //READONLY
16546 ///---- ACTIVE SUBSCREENS ONLY
16547 case SUBDATACURSORPOS:
16548 {
16549 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16550 {
16551 SubscrPage& pg = sub->cur_page();
16552 //Should this be sanity checked? Or should nulling out
16553 // the cursor by setting it invalid be allowed? -Em
16554 pg.cursor_pos = vbound(value/10000,0,255);
16555 }
16556 break;
16557 }
16558 case SUBDATASCRIPT:
16559 {
16560 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16561 sub->script = vbound(value/10000,0,NUMSCRIPTSSUBSCREEN-1);
16562 break;
16563 }
16564
16565 case SUBDATATRANSLEFTTY:
16566 {
16567 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16568 {
16569 auto& trans = sub->trans_left;
16570 trans.type = vbound(value/10000,0,sstrMAX-1);
16571 }
16572 break;
16573 }
16574 case SUBDATATRANSLEFTSFX:
16575 {
16576 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16577 {
16578 auto& trans = sub->trans_left;
16579 trans.tr_sfx = vbound(value/10000,0,255);
16580 }
16581 break;
16582 }
16583 case SUBDATATRANSRIGHTTY:
16584 {
16585 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16586 {
16587 auto& trans = sub->trans_right;
16588 trans.type = vbound(value/10000,0,sstrMAX-1);
16589 }
16590 break;
16591 }
16592 case SUBDATATRANSRIGHTSFX:
16593 {
16594 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16595 {
16596 auto& trans = sub->trans_right;
16597 trans.tr_sfx = vbound(value/10000,0,255);
16598 }
16599 break;
16600 }
16601 case SUBDATASELECTORDSTX:
16602 {
16603 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16604 sub->selector_setting.x = vbound(value/10000,-32768,32767);
16605 break;
16606 }
16607 case SUBDATASELECTORDSTY:
16608 {
16609 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16610 sub->selector_setting.y = vbound(value/10000,-32768,32767);
16611 break;
16612 }
16613 case SUBDATASELECTORDSTW:
16614 {
16615 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16616 sub->selector_setting.w = vbound(value/10000,-32768,32767);
16617 break;
16618 }
16619 case SUBDATASELECTORDSTH:
16620 {
16621 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16622 sub->selector_setting.h = vbound(value/10000,-32768,32767);
16623 break;
16624 }
16625 ///---- CURRENTLY OPEN ACTIVE SUBSCREEN ONLY
16626 case SUBDATATRANSCLK:
16627 {
16628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16629 {
16630
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(sub != new_subscreen_active)
16631 Z_scripterrlog("'subscreendata->TransClock' is only"
16632 " valid for the current active subscreen!\n");
16633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 else if(subscreen_open)
16634 {
16635 11 int val = value/10000;
16636
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(val < 0)
16637 subscrpg_clear_animation();
16638
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 else if(!subscr_pg_animating)
16639 {
16640 11 SubscrTransition tr = subscr_pg_transition;
16641 11 tr.tr_sfx = 0;
16642 11 subscrpg_animate(subscr_pg_from,subscr_pg_to,tr,*new_subscreen_active);
16643 11 subscr_pg_clk = val;
16644 11 }
16645 else subscr_pg_clk = val;
16646 11 }
16647 11 }
16648 11 break;
16649 }
16650 case SUBDATATRANSTY:
16651 {
16652
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16653 {
16654 11 auto& trans = subscr_pg_transition;
16655
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(sub != new_subscreen_active)
16656 Z_scripterrlog("'subscreendata->TransType' is only"
16657 " valid for the current active subscreen!\n");
16658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 else if(subscreen_open)
16659 11 trans.type = vbound(value/10000,0,sstrMAX-1);
16660 11 }
16661 11 break;
16662 }
16663 case SUBDATATRANSFROMPG:
16664 {
16665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16666 {
16667
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(sub != new_subscreen_active)
16668 Z_scripterrlog("'subscreendata->TransFromPage' is only"
16669 " valid for the current active subscreen!\n");
16670
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 else if(subscreen_open)
16671 11 subscr_pg_from = vbound(value/10000,0,sub->pages.size()-1);
16672 11 }
16673 11 break;
16674 }
16675 case SUBDATATRANSTOPG:
16676 {
16677
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ZCSubscreen* sub = checkSubData(ri->subdataref, sstACTIVE))
16678 {
16679
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(sub != new_subscreen_active)
16680 Z_scripterrlog("'subscreendata->TransToPage' is only"
16681 " valid for the current active subscreen!\n");
16682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 else if(subscreen_open)
16683 11 subscr_pg_to = vbound(value/10000,0,sub->pages.size()-1);
16684 11 }
16685 11 break;
16686 }
16687
16688 ///----------------------------------------------------------------------------------------------------//
16689 case SUBPGINDEX: break; //READ-ONLY
16690 case SUBPGNUMWIDG: break; //READ-ONLY
16691 case SUBPGSUBDATA: break; //READ-ONLY
16692 case SUBPGCURSORPOS:
16693 {
16694 if(SubscrPage* pg = checkSubPage(ri->subpageref))
16695 pg->cursor_pos = vbound(value/10000,0,255);
16696 break;
16697 }
16698 ///----------------------------------------------------------------------------------------------------//
16699 ///---- ANY WIDGET TYPE
16700 case SUBWIDGTYPE: break; //READ-ONLY
16701 case SUBWIDGINDEX: break; //READ-ONLY
16702 case SUBWIDGPAGE: break; //READ-ONLY
16703 case SUBWIDGDISPITM: break; //READ-ONLY
16704 case SUBWIDGEQPITM: break; //READ-ONLY
16705 case SUBWIDGPOS:
16706 {
16707 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16708 widg->pos = vbound(value/10000,0,255);
16709 break;
16710 }
16711 case SUBWIDGX:
16712 {
16713
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 132 times.
132 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16714 132 widg->x = vbound(value/10000,-32768,32767);
16715 132 break;
16716 }
16717 case SUBWIDGY:
16718 {
16719
1/2
✓ Branch 0 taken 4247 times.
✗ Branch 1 not taken.
4247 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16720 4247 widg->y = vbound(value/10000,-32768,32767);
16721 4247 break;
16722 }
16723 case SUBWIDGW:
16724 {
16725 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16726 widg->w = vbound(value/10000,0,65535);
16727 break;
16728 }
16729 case SUBWIDGH:
16730 {
16731 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16732 widg->h = vbound(value/10000,0,65535);
16733 break;
16734 }
16735 case SUBWIDGREQCOUNTER:
16736 {
16737 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16738 widg->req_counter = vbound(value/10000,sscMIN,MAX_COUNTERS);
16739 break;
16740 }
16741 case SUBWIDGREQCOUNTERCOND:
16742 {
16743 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16744 widg->req_counter_cond_type = vbound(value/10000,CONDTY_NONE,CONDTY_MAX-1);
16745 break;
16746 }
16747 case SUBWIDGREQCOUNTERVAL:
16748 {
16749 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16750 widg->req_counter_val = vbound(value/10000,0,65535);
16751 break;
16752 }
16753 case SUBWIDGREQLITEMS:
16754 {
16755 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16756 widg->req_litems = vbound(value/10000,0,liALL);
16757 break;
16758 }
16759 case SUBWIDGREQLITEMLEVEL:
16760 {
16761 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16762 widg->req_litem_level = vbound(value/10000,-1,MAXLEVELS);
16763 break;
16764 }
16765 case SUBWIDGREQSCRIPTDISABLED:
16766 {
16767 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16768 widg->is_disabled = value != 0;
16769 break;
16770 }
16771 ///---- ACTIVE SUBSCREENS ONLY
16772 case SUBWIDGSELECTORDSTX:
16773 {
16774 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16775 widg->selector_override.x = vbound(value/10000,-32768,32767);
16776 break;
16777 }
16778 case SUBWIDGSELECTORDSTY:
16779 {
16780 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16781 widg->selector_override.y = vbound(value/10000,-32768,32767);
16782 break;
16783 }
16784 case SUBWIDGSELECTORDSTW:
16785 {
16786 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16787 widg->selector_override.w = vbound(value/10000,-32768,32767);
16788 break;
16789 }
16790 case SUBWIDGSELECTORDSTH:
16791 {
16792 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16793 widg->selector_override.h = vbound(value/10000,-32768,32767);
16794 break;
16795 }
16796
16797 case SUBWIDGPRESSSCRIPT:
16798 {
16799 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16800 widg->generic_script = vbound(value/10000,0,NUMSCRIPTSGENERIC-1);
16801 break;
16802 }
16803 case SUBWIDGPGMODE:
16804 {
16805 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16806 widg->pg_mode = vbound(value/10000,0,PGGOTO_MAX-1);
16807 break;
16808 }
16809 case SUBWIDGPGTARG:
16810 {
16811 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16812 widg->pg_targ = vbound(value/10000,0,MAX_SUBSCR_PAGES-1);
16813 break;
16814 }
16815
16816 case SUBWIDGTRANSPGTY:
16817 {
16818 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16819 {
16820 auto& trans = widg->pg_trans;
16821 trans.type = vbound(value/10000,0,sstrMAX-1);
16822 }
16823 break;
16824 }
16825 case SUBWIDGTRANSPGSFX:
16826 {
16827 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref, sstACTIVE))
16828 {
16829 auto& trans = widg->pg_trans;
16830 trans.tr_sfx = vbound(value/10000,0,255);
16831 }
16832 break;
16833 }
16834 case SUBWIDGTY_FONT:
16835 {
16836 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16837 {
16838 auto val = vbound(value/10000,0,font_max-1);
16839 auto ty = widg->getType();
16840 switch(ty)
16841 {
16842 case widgTEXT:
16843 ((SW_Text*)widg)->fontid = val;
16844 break;
16845 case widgTEXTBOX:
16846 ((SW_TextBox*)widg)->fontid = val;
16847 break;
16848 case widgSELECTEDTEXT:
16849 ((SW_SelectedText*)widg)->fontid = val;
16850 break;
16851 case widgTIME:
16852 ((SW_Time*)widg)->fontid = val;
16853 break;
16854 case widgCOUNTER:
16855 ((SW_Counter*)widg)->fontid = val;
16856 break;
16857 case widgBTNCOUNTER:
16858 ((SW_BtnCounter*)widg)->fontid = val;
16859 break;
16860 case widgOLDCTR:
16861 ((SW_Counters*)widg)->fontid = val;
16862 break;
16863 case widgMMAPTITLE:
16864 ((SW_MMapTitle*)widg)->fontid = val;
16865 break;
16866 default:
16867 bad_subwidg_type(false, ty);
16868 break;
16869 }
16870 }
16871 break;
16872 }
16873 case SUBWIDGTY_ALIGN:
16874 {
16875 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16876 {
16877 auto val = vbound(value/10000,0,sstaMAX-1);
16878 auto ty = widg->getType();
16879 switch(ty)
16880 {
16881 case widgTEXT:
16882 ((SW_Text*)widg)->align = val;
16883 break;
16884 case widgTEXTBOX:
16885 ((SW_TextBox*)widg)->align = val;
16886 break;
16887 case widgSELECTEDTEXT:
16888 ((SW_SelectedText*)widg)->align = val;
16889 break;
16890 case widgTIME:
16891 ((SW_Time*)widg)->align = val;
16892 break;
16893 case widgCOUNTER:
16894 ((SW_Counter*)widg)->align = val;
16895 break;
16896 case widgBTNCOUNTER:
16897 ((SW_BtnCounter*)widg)->align = val;
16898 break;
16899 case widgMMAPTITLE:
16900 ((SW_MMapTitle*)widg)->align = val;
16901 break;
16902 default:
16903 bad_subwidg_type(false, ty);
16904 break;
16905 }
16906 }
16907 break;
16908 }
16909 case SUBWIDGTY_SHADOWTY:
16910 {
16911 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16912 {
16913 auto val = vbound(value/10000,0,sstsMAX-1);
16914 auto ty = widg->getType();
16915 switch(ty)
16916 {
16917 case widgTEXT:
16918 ((SW_Text*)widg)->shadtype = val;
16919 break;
16920 case widgTEXTBOX:
16921 ((SW_TextBox*)widg)->shadtype = val;
16922 break;
16923 case widgSELECTEDTEXT:
16924 ((SW_SelectedText*)widg)->shadtype = val;
16925 break;
16926 case widgTIME:
16927 ((SW_Time*)widg)->shadtype = val;
16928 break;
16929 case widgCOUNTER:
16930 ((SW_Counter*)widg)->shadtype = val;
16931 break;
16932 case widgBTNCOUNTER:
16933 ((SW_BtnCounter*)widg)->shadtype = val;
16934 break;
16935 case widgOLDCTR:
16936 ((SW_Counters*)widg)->shadtype = val;
16937 break;
16938 case widgMMAPTITLE:
16939 ((SW_MMapTitle*)widg)->shadtype = val;
16940 break;
16941 default:
16942 bad_subwidg_type(false, ty);
16943 break;
16944 }
16945 }
16946 break;
16947 }
16948 case SUBWIDGTY_COLOR_TXT:
16949 {
16950 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16951 {
16952 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
16953 auto ty = widg->getType();
16954 switch(ty)
16955 {
16956 case widgTEXT:
16957 ((SW_Text*)widg)->c_text.set_int_color(val);
16958 break;
16959 case widgTEXTBOX:
16960 ((SW_TextBox*)widg)->c_text.set_int_color(val);
16961 break;
16962 case widgSELECTEDTEXT:
16963 ((SW_SelectedText*)widg)->c_text.set_int_color(val);
16964 break;
16965 case widgTIME:
16966 ((SW_Time*)widg)->c_text.set_int_color(val);
16967 break;
16968 case widgCOUNTER:
16969 ((SW_Counter*)widg)->c_text.set_int_color(val);
16970 break;
16971 case widgBTNCOUNTER:
16972 ((SW_BtnCounter*)widg)->c_text.set_int_color(val);
16973 break;
16974 case widgOLDCTR:
16975 ((SW_Counters*)widg)->c_text.set_int_color(val);
16976 break;
16977 case widgMMAPTITLE:
16978 ((SW_MMapTitle*)widg)->c_text.set_int_color(val);
16979 break;
16980 case widgMCGUFF_FRAME:
16981 ((SW_TriFrame*)widg)->c_number.set_int_color(val);
16982 break;
16983 default:
16984 bad_subwidg_type(false, ty);
16985 break;
16986 }
16987 }
16988 break;
16989 }
16990 case SUBWIDGTY_COLOR_SHD:
16991 {
16992 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
16993 {
16994 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
16995 auto ty = widg->getType();
16996 switch(ty)
16997 {
16998 case widgTEXT:
16999 ((SW_Text*)widg)->c_shadow.set_int_color(val);
17000 break;
17001 case widgTEXTBOX:
17002 ((SW_TextBox*)widg)->c_shadow.set_int_color(val);
17003 break;
17004 case widgSELECTEDTEXT:
17005 ((SW_SelectedText*)widg)->c_shadow.set_int_color(val);
17006 break;
17007 case widgTIME:
17008 ((SW_Time*)widg)->c_shadow.set_int_color(val);
17009 break;
17010 case widgCOUNTER:
17011 ((SW_Counter*)widg)->c_shadow.set_int_color(val);
17012 break;
17013 case widgBTNCOUNTER:
17014 ((SW_BtnCounter*)widg)->c_shadow.set_int_color(val);
17015 break;
17016 case widgOLDCTR:
17017 ((SW_Counters*)widg)->c_shadow.set_int_color(val);
17018 break;
17019 case widgMMAPTITLE:
17020 ((SW_MMapTitle*)widg)->c_shadow.set_int_color(val);
17021 break;
17022 default:
17023 bad_subwidg_type(false, ty);
17024 break;
17025 }
17026 }
17027 break;
17028 }
17029 case SUBWIDGTY_COLOR_BG:
17030 {
17031 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17032 {
17033 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17034 auto ty = widg->getType();
17035 switch(ty)
17036 {
17037 case widgTEXT:
17038 ((SW_Text*)widg)->c_bg.set_int_color(val);
17039 break;
17040 case widgTEXTBOX:
17041 ((SW_TextBox*)widg)->c_bg.set_int_color(val);;
17042 break;
17043 case widgSELECTEDTEXT:
17044 ((SW_SelectedText*)widg)->c_bg.set_int_color(val);;
17045 break;
17046 case widgTIME:
17047 ((SW_Time*)widg)->c_bg.set_int_color(val);
17048 break;
17049 case widgCOUNTER:
17050 ((SW_Counter*)widg)->c_bg.set_int_color(val);
17051 break;
17052 case widgBTNCOUNTER:
17053 ((SW_BtnCounter*)widg)->c_bg.set_int_color(val);
17054 break;
17055 case widgOLDCTR:
17056 ((SW_Counters*)widg)->c_bg.set_int_color(val);
17057 break;
17058 case widgMMAPTITLE:
17059 ((SW_MMapTitle*)widg)->c_bg.set_int_color(val);
17060 break;
17061 case widgBGCOLOR:
17062 ((SW_Clear*)widg)->c_bg.set_int_color(val);
17063 break;
17064 case widgCOUNTERPERCBAR:
17065 ((SW_CounterPercentBar*)widg)->c_bg.set_int_color(val);
17066 break;
17067 default:
17068 bad_subwidg_type(false, ty);
17069 break;
17070 }
17071 }
17072 break;
17073 }
17074
17075 case SUBWIDGTY_COLOR_TXT2:
17076 {
17077 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17078 {
17079 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17080 auto ty = widg->getType();
17081 switch(ty)
17082 {
17083 case widgCOUNTER:
17084 ((SW_Counter*)widg)->c_text2.set_int_color(val);
17085 break;
17086 case widgBTNCOUNTER:
17087 ((SW_BtnCounter*)widg)->c_text2.set_int_color(val);
17088 break;
17089 default:
17090 bad_subwidg_type(false, ty);
17091 break;
17092 }
17093 }
17094 break;
17095 }
17096 case SUBWIDGTY_COLOR_SHD2:
17097 {
17098 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17099 {
17100 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17101 auto ty = widg->getType();
17102 switch(ty)
17103 {
17104 case widgCOUNTER:
17105 ((SW_Counter*)widg)->c_shadow2.set_int_color(val);
17106 break;
17107 case widgBTNCOUNTER:
17108 ((SW_BtnCounter*)widg)->c_shadow2.set_int_color(val);
17109 break;
17110 default:
17111 bad_subwidg_type(false, ty);
17112 break;
17113 }
17114 }
17115 break;
17116 }
17117 case SUBWIDGTY_COLOR_BG2:
17118 {
17119 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17120 {
17121 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17122 auto ty = widg->getType();
17123 switch(ty)
17124 {
17125 case widgCOUNTER:
17126 ((SW_Counter*)widg)->c_bg2.set_int_color(val);
17127 break;
17128 case widgBTNCOUNTER:
17129 ((SW_BtnCounter*)widg)->c_bg2.set_int_color(val);
17130 break;
17131 default:
17132 bad_subwidg_type(false, ty);
17133 break;
17134 }
17135 }
17136 break;
17137 }
17138
17139 case SUBWIDGTY_COLOR_OLINE:
17140 {
17141 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17142 {
17143 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17144 auto ty = widg->getType();
17145 switch(ty)
17146 {
17147 case widgLINE:
17148 ((SW_Line*)widg)->c_line.set_int_color(val);
17149 break;
17150 case widgRECT:
17151 ((SW_Rect*)widg)->c_outline.set_int_color(val);
17152 break;
17153 case widgMCGUFF_FRAME:
17154 ((SW_TriFrame*)widg)->c_outline.set_int_color(val);
17155 break;
17156 default:
17157 bad_subwidg_type(false, ty);
17158 break;
17159 }
17160 }
17161 break;
17162 }
17163
17164 case SUBWIDGTY_COLOR_FILL:
17165 {
17166 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17167 {
17168 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17169 auto ty = widg->getType();
17170 switch(ty)
17171 {
17172 case widgRECT:
17173 ((SW_Rect*)widg)->c_fill.set_int_color(val);
17174 break;
17175 case widgCOUNTERPERCBAR:
17176 ((SW_CounterPercentBar*)widg)->c_fill.set_int_color(val);
17177 break;
17178 default:
17179 bad_subwidg_type(false, ty);
17180 break;
17181 }
17182 }
17183 break;
17184 }
17185 case SUBWIDGTY_BUTTON:
17186 {
17187 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17188 {
17189 auto val = vbound(value/10000,0,3);
17190 auto ty = widg->getType();
17191 switch(ty)
17192 {
17193 case widgBTNITM:
17194 ((SW_ButtonItem*)widg)->btn = val;
17195 break;
17196 case widgBTNCOUNTER:
17197 ((SW_BtnCounter*)widg)->btn = val;
17198 break;
17199 default:
17200 bad_subwidg_type(false, ty);
17201 break;
17202 }
17203 }
17204 break;
17205 }
17206 case SUBWIDGTY_MINDIG:
17207 {
17208 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17209 {
17210 auto val = vbound(value/10000,0,5);
17211 auto ty = widg->getType();
17212 switch(ty)
17213 {
17214 case widgCOUNTER:
17215 ((SW_Counter*)widg)->mindigits = val;
17216 break;
17217 case widgBTNCOUNTER:
17218 ((SW_BtnCounter*)widg)->mindigits = val;
17219 break;
17220 case widgOLDCTR:
17221 ((SW_Counters*)widg)->digits = val;
17222 break;
17223 default:
17224 bad_subwidg_type(false, ty);
17225 break;
17226 }
17227 }
17228 break;
17229 }
17230 case SUBWIDGTY_MAXDIG:
17231 {
17232 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17233 {
17234 auto val = vbound(value/10000,0,5);
17235 auto ty = widg->getType();
17236 switch(ty)
17237 {
17238 case widgCOUNTER:
17239 ((SW_Counter*)widg)->maxdigits = val;
17240 break;
17241 case widgBTNCOUNTER:
17242 ((SW_BtnCounter*)widg)->maxdigits = val;
17243 break;
17244 default:
17245 bad_subwidg_type(false, ty);
17246 break;
17247 }
17248 }
17249 break;
17250 }
17251 case SUBWIDGTY_INFITM:
17252 {
17253 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17254 {
17255 auto val = vbound(value/10000,-1,MAXITEMS-1);
17256 auto ty = widg->getType();
17257 switch(ty)
17258 {
17259 case widgCOUNTER:
17260 ((SW_Counter*)widg)->infitm = val;
17261 break;
17262 case widgOLDCTR:
17263 ((SW_Counters*)widg)->infitm = val;
17264 break;
17265 case widgLGAUGE:
17266 case widgMGAUGE:
17267 case widgMISCGAUGE:
17268 ((SW_GaugePiece*)widg)->inf_item = val;
17269 break;
17270 default:
17271 bad_subwidg_type(false, ty);
17272 break;
17273 }
17274 }
17275 break;
17276 }
17277 case SUBWIDGTY_INFCHAR:
17278 {
17279 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17280 {
17281 char val = vbound(value/10000,0,255);
17282 auto ty = widg->getType();
17283 switch(ty)
17284 {
17285 case widgCOUNTER:
17286 ((SW_Counter*)widg)->infchar = val;
17287 break;
17288 case widgBTNCOUNTER:
17289 ((SW_BtnCounter*)widg)->infchar = val;
17290 break;
17291 case widgOLDCTR:
17292 ((SW_Counters*)widg)->infchar = val;
17293 break;
17294 default:
17295 bad_subwidg_type(false, ty);
17296 break;
17297 }
17298 }
17299 break;
17300 }
17301 case SUBWIDGTY_COSTIND:
17302 {
17303 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17304 {
17305 auto val = vbound(value/10000,0,1);
17306 auto ty = widg->getType();
17307 switch(ty)
17308 {
17309 case widgBTNCOUNTER:
17310 ((SW_BtnCounter*)widg)->costind = val;
17311 break;
17312 default:
17313 bad_subwidg_type(false, ty);
17314 break;
17315 }
17316 }
17317 break;
17318 }
17319 case SUBWIDGTY_COLOR_PLAYER:
17320 {
17321 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17322 {
17323 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17324 auto ty = widg->getType();
17325 switch(ty)
17326 {
17327 case widgMMAP:
17328 ((SW_MMap*)widg)->c_plr.set_int_color(val);
17329 break;
17330 case widgLMAP:
17331 ((SW_LMap*)widg)->c_plr.set_int_color(val);
17332 break;
17333 default:
17334 bad_subwidg_type(false, ty);
17335 break;
17336 }
17337 }
17338 break;
17339 }
17340 case SUBWIDGTY_COLOR_CMPBLNK:
17341 {
17342 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17343 {
17344 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17345 auto ty = widg->getType();
17346 switch(ty)
17347 {
17348 case widgMMAP:
17349 ((SW_MMap*)widg)->c_cmp_blink.set_int_color(val);
17350 break;
17351 default:
17352 bad_subwidg_type(false, ty);
17353 break;
17354 }
17355 }
17356 break;
17357 }
17358 case SUBWIDGTY_COLOR_CMPOFF:
17359 {
17360 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17361 {
17362 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17363 auto ty = widg->getType();
17364 switch(ty)
17365 {
17366 case widgMMAP:
17367 ((SW_MMap*)widg)->c_cmp_off.set_int_color(val);
17368 break;
17369 default:
17370 bad_subwidg_type(false, ty);
17371 break;
17372 }
17373 }
17374 break;
17375 }
17376 case SUBWIDGTY_COLOR_ROOM:
17377 {
17378 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17379 {
17380 auto val = vbound(value/10000,MIN_SUBSCR_COLOR,MAX_SUBSCR_COLOR);
17381 auto ty = widg->getType();
17382 switch(ty)
17383 {
17384 case widgLMAP:
17385 ((SW_LMap*)widg)->c_room.set_int_color(val);
17386 break;
17387 default:
17388 bad_subwidg_type(false, ty);
17389 break;
17390 }
17391 }
17392 break;
17393 }
17394 case SUBWIDGTY_ITEMCLASS:
17395 {
17396 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17397 {
17398 auto val = vbound(value/10000,0,itype_maxusable-1);
17399 auto ty = widg->getType();
17400 switch(ty)
17401 {
17402 case widgITEMSLOT:
17403 ((SW_ItemSlot*)widg)->iclass = val;
17404 break;
17405 default:
17406 bad_subwidg_type(false, ty);
17407 break;
17408 }
17409 }
17410 break;
17411 }
17412 case SUBWIDGTY_ITEMID:
17413 {
17414 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17415 {
17416 auto val = vbound(value/10000,-1,MAXITEMS-1);
17417 auto ty = widg->getType();
17418 switch(ty)
17419 {
17420 case widgITEMSLOT:
17421 ((SW_ItemSlot*)widg)->iid = val;
17422 break;
17423 default:
17424 bad_subwidg_type(false, ty);
17425 break;
17426 }
17427 }
17428 break;
17429 }
17430 case SUBWIDGTY_FRAMETILE:
17431 {
17432 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17433 {
17434 auto val = vbound(value/10000,0,NEWMAXTILES-1);
17435 auto ty = widg->getType();
17436 switch(ty)
17437 {
17438 case widgMCGUFF_FRAME:
17439 ((SW_TriFrame*)widg)->frame_tile = val;
17440 break;
17441 default:
17442 bad_subwidg_type(false, ty);
17443 break;
17444 }
17445 }
17446 break;
17447 }
17448 case SUBWIDGTY_FRAMECSET:
17449 {
17450 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17451 {
17452 auto val = vbound(value/10000,0,15);
17453 auto ty = widg->getType();
17454 switch(ty)
17455 {
17456 case widgMCGUFF_FRAME:
17457 ((SW_TriFrame*)widg)->frame_cset = val;
17458 break;
17459 default:
17460 bad_subwidg_type(false, ty);
17461 break;
17462 }
17463 }
17464 break;
17465 }
17466 case SUBWIDGTY_PIECETILE:
17467 {
17468 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17469 {
17470 auto val = vbound(value/10000,0,NEWMAXTILES-1);
17471 auto ty = widg->getType();
17472 switch(ty)
17473 {
17474 case widgMCGUFF_FRAME:
17475 ((SW_TriFrame*)widg)->piece_tile = val;
17476 break;
17477 default:
17478 bad_subwidg_type(false, ty);
17479 break;
17480 }
17481 }
17482 break;
17483 }
17484 case SUBWIDGTY_PIECECSET:
17485 {
17486 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17487 {
17488 auto val = vbound(value/10000,0,15);
17489 auto ty = widg->getType();
17490 switch(ty)
17491 {
17492 case widgMCGUFF_FRAME:
17493 ((SW_TriFrame*)widg)->piece_cset = val;
17494 break;
17495 default:
17496 bad_subwidg_type(false, ty);
17497 break;
17498 }
17499 }
17500 break;
17501 }
17502 case SUBWIDGTY_FLIP:
17503 {
17504 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17505 {
17506 auto val = vbound(value/10000,0,15);
17507 auto ty = widg->getType();
17508 switch(ty)
17509 {
17510 case widgMCGUFF:
17511 ((SW_McGuffin*)widg)->flip = val;
17512 break;
17513 case widgTILEBLOCK:
17514 ((SW_TileBlock*)widg)->flip = val;
17515 break;
17516 case widgMINITILE:
17517 ((SW_MiniTile*)widg)->flip = val;
17518 break;
17519 default:
17520 bad_subwidg_type(false, ty);
17521 break;
17522 }
17523 }
17524 break;
17525 }
17526 case SUBWIDGTY_NUMBER:
17527 {
17528 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17529 {
17530 auto val = vbound(value/10000,0,255);
17531 auto ty = widg->getType();
17532 switch(ty)
17533 {
17534 case widgMCGUFF:
17535 ((SW_McGuffin*)widg)->number = val;
17536 break;
17537 default:
17538 bad_subwidg_type(false, ty);
17539 break;
17540 }
17541 }
17542 break;
17543 }
17544 case SUBWIDGTY_FRAMES:
17545 {
17546 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17547 {
17548 auto val = vbound(value/10000,1,65535);
17549 auto ty = widg->getType();
17550 switch(ty)
17551 {
17552 case widgLGAUGE:
17553 case widgMGAUGE:
17554 case widgMISCGAUGE:
17555 ((SW_GaugePiece*)widg)->frames = val;
17556 break;
17557 default:
17558 bad_subwidg_type(false, ty);
17559 break;
17560 }
17561 }
17562 break;
17563 }
17564 case SUBWIDGTY_SPEED:
17565 {
17566 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17567 {
17568 auto val = vbound(value/10000,1,65535);
17569 auto ty = widg->getType();
17570 switch(ty)
17571 {
17572 case widgLGAUGE:
17573 case widgMGAUGE:
17574 case widgMISCGAUGE:
17575 ((SW_GaugePiece*)widg)->speed = val;
17576 break;
17577 default:
17578 bad_subwidg_type(false, ty);
17579 break;
17580 }
17581 }
17582 break;
17583 }
17584 case SUBWIDGTY_DELAY:
17585 {
17586 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17587 {
17588 auto val = vbound(value/10000,0,65535);
17589 auto ty = widg->getType();
17590 switch(ty)
17591 {
17592 case widgLGAUGE:
17593 case widgMGAUGE:
17594 case widgMISCGAUGE:
17595 ((SW_GaugePiece*)widg)->delay = val;
17596 break;
17597 default:
17598 bad_subwidg_type(false, ty);
17599 break;
17600 }
17601 }
17602 break;
17603 }
17604 case SUBWIDGTY_CONTAINER:
17605 {
17606 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17607 {
17608 auto val = vbound(value/10000,0,65535);
17609 auto ty = widg->getType();
17610 switch(ty)
17611 {
17612 case widgLGAUGE:
17613 case widgMGAUGE:
17614 case widgMISCGAUGE:
17615 ((SW_GaugePiece*)widg)->container = val;
17616 break;
17617 default:
17618 bad_subwidg_type(false, ty);
17619 break;
17620 }
17621 }
17622 break;
17623 }
17624 case SUBWIDGTY_GAUGE_WID:
17625 {
17626 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17627 {
17628 auto val = vbound(value/10000,1,32)-1;
17629 auto ty = widg->getType();
17630 switch(ty)
17631 {
17632 case widgLGAUGE:
17633 case widgMGAUGE:
17634 case widgMISCGAUGE:
17635 ((SW_GaugePiece*)widg)->gauge_wid = val;
17636 break;
17637 default:
17638 bad_subwidg_type(false, ty);
17639 break;
17640 }
17641 }
17642 break;
17643 }
17644 case SUBWIDGTY_GAUGE_HEI:
17645 {
17646 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17647 {
17648 auto val = vbound(value/10000,1,32)-1;
17649 auto ty = widg->getType();
17650 switch(ty)
17651 {
17652 case widgLGAUGE:
17653 case widgMGAUGE:
17654 case widgMISCGAUGE:
17655 ((SW_GaugePiece*)widg)->gauge_hei = val;
17656 break;
17657 default:
17658 bad_subwidg_type(false, ty);
17659 break;
17660 }
17661 }
17662 break;
17663 }
17664 case SUBWIDGTY_UNITS:
17665 {
17666 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17667 {
17668 auto val = vbound(value/10000,1,256);
17669 auto ty = widg->getType();
17670 switch(ty)
17671 {
17672 case widgLGAUGE:
17673 case widgMGAUGE:
17674 case widgMISCGAUGE:
17675 ((SW_GaugePiece*)widg)->unit_per_frame = val-1;
17676 break;
17677 default:
17678 bad_subwidg_type(false, ty);
17679 break;
17680 }
17681 }
17682 break;
17683 }
17684 case SUBWIDGTY_HSPACE:
17685 {
17686 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17687 {
17688 auto val = vbound(value/10000,-128,127);
17689 auto ty = widg->getType();
17690 switch(ty)
17691 {
17692 case widgLGAUGE:
17693 case widgMGAUGE:
17694 case widgMISCGAUGE:
17695 ((SW_GaugePiece*)widg)->hspace = val;
17696 break;
17697 default:
17698 bad_subwidg_type(false, ty);
17699 break;
17700 }
17701 }
17702 break;
17703 }
17704 case SUBWIDGTY_VSPACE:
17705 {
17706 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17707 {
17708 auto val = vbound(value/10000,-128,127);
17709 auto ty = widg->getType();
17710 switch(ty)
17711 {
17712 case widgLGAUGE:
17713 case widgMGAUGE:
17714 case widgMISCGAUGE:
17715 ((SW_GaugePiece*)widg)->vspace = val;
17716 break;
17717 default:
17718 bad_subwidg_type(false, ty);
17719 break;
17720 }
17721 }
17722 break;
17723 }
17724 case SUBWIDGTY_GRIDX:
17725 {
17726 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17727 {
17728 auto val = vbound(value/10000,-32768,32767);
17729 auto ty = widg->getType();
17730 switch(ty)
17731 {
17732 case widgLGAUGE:
17733 case widgMGAUGE:
17734 case widgMISCGAUGE:
17735 ((SW_GaugePiece*)widg)->grid_xoff = val;
17736 break;
17737 default:
17738 bad_subwidg_type(false, ty);
17739 break;
17740 }
17741 }
17742 break;
17743 }
17744 case SUBWIDGTY_GRIDY:
17745 {
17746 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17747 {
17748 auto val = vbound(value/10000,-32768,32767);
17749 auto ty = widg->getType();
17750 switch(ty)
17751 {
17752 case widgLGAUGE:
17753 case widgMGAUGE:
17754 case widgMISCGAUGE:
17755 ((SW_GaugePiece*)widg)->grid_yoff = val;
17756 break;
17757 default:
17758 bad_subwidg_type(false, ty);
17759 break;
17760 }
17761 }
17762 break;
17763 }
17764 case SUBWIDGTY_ANIMVAL:
17765 {
17766 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17767 {
17768 auto val = vbound(value/10000,0,65535);
17769 auto ty = widg->getType();
17770 switch(ty)
17771 {
17772 case widgLGAUGE:
17773 case widgMGAUGE:
17774 case widgMISCGAUGE:
17775 ((SW_GaugePiece*)widg)->anim_val = val;
17776 break;
17777 default:
17778 bad_subwidg_type(false, ty);
17779 break;
17780 }
17781 }
17782 break;
17783 }
17784 case SUBWIDGTY_SHOWDRAIN:
17785 {
17786 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17787 {
17788 auto val = vbound(value/10000,-1,32767);
17789 auto ty = widg->getType();
17790 switch(ty)
17791 {
17792 case widgMGAUGE:
17793 ((SW_MagicGaugePiece*)widg)->showdrain = val;
17794 break;
17795 default:
17796 bad_subwidg_type(false, ty);
17797 break;
17798 }
17799 }
17800 break;
17801 }
17802 case SUBWIDGTY_PERCONTAINER:
17803 {
17804 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17805 {
17806 auto val = vbound(value/10000,1,65535);
17807 auto ty = widg->getType();
17808 switch(ty)
17809 {
17810 case widgMISCGAUGE:
17811 ((SW_MiscGaugePiece*)widg)->per_container = val;
17812 break;
17813 default:
17814 bad_subwidg_type(false, ty);
17815 break;
17816 }
17817 }
17818 break;
17819 }
17820 case SUBWIDGTY_TABSIZE:
17821 {
17822 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17823 {
17824 auto val = vbound(value/10000,0,255);
17825 auto ty = widg->getType();
17826 switch(ty)
17827 {
17828 case widgTEXTBOX:
17829 ((SW_TextBox*)widg)->tabsize = val;
17830 break;
17831 case widgSELECTEDTEXT:
17832 ((SW_SelectedText*)widg)->tabsize = val;
17833 break;
17834 default:
17835 bad_subwidg_type(false, ty);
17836 break;
17837 }
17838 }
17839 break;
17840 }
17841 case SUBWIDGTY_LITEMS:
17842 {
17843 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
17844 {
17845 auto val = vbound(value/10000,0,255);
17846 auto ty = widg->getType();
17847 switch(ty)
17848 {
17849 case widgMMAP:
17850 ((SW_MMap*)widg)->compass_litems = val;
17851 break;
17852 default:
17853 bad_subwidg_type(false, ty);
17854 break;
17855 }
17856 }
17857 break;
17858 }
17859
17860 default:
17861 {
17862
2/2
✓ Branch 0 taken 17300163 times.
✓ Branch 1 taken 26483000 times.
43783163 if (zasm_array_supports(arg))
17863 {
17864 17300163 int ref_arg = get_register_ref_dependency(arg).value_or(0);
17865
2/2
✓ Branch 0 taken 7963407 times.
✓ Branch 1 taken 9336756 times.
17300163 int ref = ref_arg ? get_ref(ref_arg) : 0;
17866 17300163 zasm_array_set(arg, ref, ri->d[rINDEX] / 10000, value);
17867 17300163 }
17868 else
17869 {
17870 26483000 scripting_engine_set_register(arg, value);
17871 }
17872 }
17873 43783163 }
17874
17875 1622645979 current_zasm_register = 0;
17876 2111466290 } //end set_register
17877
17878 407 static std::map<std::string, int> name_to_slot_index_ffcmap;
17879 407 static std::map<std::string, int> name_to_slot_index_globalmap;
17880 407 static std::map<std::string, int> name_to_slot_index_genericmap;
17881 407 static std::map<std::string, int> name_to_slot_index_itemmap;
17882 407 static std::map<std::string, int> name_to_slot_index_npcmap;
17883 407 static std::map<std::string, int> name_to_slot_index_ewpnmap;
17884 407 static std::map<std::string, int> name_to_slot_index_lwpnmap;
17885 407 static std::map<std::string, int> name_to_slot_index_playermap;
17886 407 static std::map<std::string, int> name_to_slot_index_dmapmap;
17887 407 static std::map<std::string, int> name_to_slot_index_screenmap;
17888 407 static std::map<std::string, int> name_to_slot_index_itemspritemap;
17889 407 static std::map<std::string, int> name_to_slot_index_comboscriptmap;
17890 407 static std::map<std::string, int> name_to_slot_index_subscreenmap;
17891
17892 417 void script_init_name_to_slot_index_maps()
17893 {
17894 int i;
17895 #define DECL_INIT_MAP(name) \
17896 {\
17897 name_to_slot_index_##name.clear();\
17898 i = 0;\
17899 for (auto& it : name)\
17900 {\
17901 if (!name_to_slot_index_##name.contains(it.second.scriptname))\
17902 name_to_slot_index_##name[it.second.scriptname] = i;\
17903 i++;\
17904 }\
17905 }
17906
17907
4/4
✓ Branch 0 taken 213087 times.
✓ Branch 1 taken 417 times.
✓ Branch 2 taken 203884 times.
✓ Branch 3 taken 9203 times.
213504 DECL_INIT_MAP(ffcmap);
17908
4/4
✓ Branch 0 taken 3336 times.
✓ Branch 1 taken 417 times.
✓ Branch 2 taken 1932 times.
✓ Branch 3 taken 1404 times.
3753 DECL_INIT_MAP(globalmap);
17909
4/4
✓ Branch 0 taken 213087 times.
✓ Branch 1 taken 417 times.
✓ Branch 2 taken 211115 times.
✓ Branch 3 taken 1972 times.
213504 DECL_INIT_MAP(genericmap);
17910
4/4
✓ Branch 0 taken 106335 times.
✓ Branch 1 taken 417 times.
✓ Branch 2 taken 104786 times.
✓ Branch 3 taken 1549 times.
106752 DECL_INIT_MAP(itemmap);
17911
4/4
✓ Branch 0 taken 106335 times.
✓ Branch 1 taken 417 times.
✓ Branch 2 taken 105899 times.
✓ Branch 3 taken 436 times.
106752 DECL_INIT_MAP(npcmap);
17912
4/4
✓ Branch 0 taken 106335 times.
✓ Branch 1 taken 417 times.
✓ Branch 2 taken 105715 times.
✓ Branch 3 taken 620 times.
106752 DECL_INIT_MAP(ewpnmap);
17913
4/4
✓ Branch 0 taken 106335 times.
✓ Branch 1 taken 417 times.
✓ Branch 2 taken 105661 times.
✓ Branch 3 taken 674 times.
106752 DECL_INIT_MAP(lwpnmap);
17914
4/4
✓ Branch 0 taken 1668 times.
✓ Branch 1 taken 417 times.
✓ Branch 2 taken 1236 times.
✓ Branch 3 taken 432 times.
2085 DECL_INIT_MAP(playermap);
17915
4/4
✓ Branch 0 taken 106335 times.
✓ Branch 1 taken 417 times.
✓ Branch 2 taken 105519 times.
✓ Branch 3 taken 816 times.
106752 DECL_INIT_MAP(dmapmap);
17916
4/4
✓ Branch 0 taken 106335 times.
✓ Branch 1 taken 417 times.
✓ Branch 2 taken 105587 times.
✓ Branch 3 taken 748 times.
106752 DECL_INIT_MAP(screenmap);
17917
4/4
✓ Branch 0 taken 106335 times.
✓ Branch 1 taken 417 times.
✓ Branch 2 taken 105884 times.
✓ Branch 3 taken 451 times.
106752 DECL_INIT_MAP(itemspritemap);
17918
4/4
✓ Branch 0 taken 213087 times.
✓ Branch 1 taken 417 times.
✓ Branch 2 taken 212558 times.
✓ Branch 3 taken 529 times.
213504 DECL_INIT_MAP(comboscriptmap);
17919
4/4
✓ Branch 0 taken 106335 times.
✓ Branch 1 taken 417 times.
✓ Branch 2 taken 105912 times.
✓ Branch 3 taken 423 times.
106752 DECL_INIT_MAP(subscreenmap);
17920 417 }
17921
17922 10246317 static void do_get_script_index_by_name(const std::map<std::string, int>& name_to_slot_index)
17923 {
17924 10246317 int32_t arrayptr = get_register(sarg1);
17925 10246317 string name;
17926 10246317 int32_t num=-1;
17927
1/2
✓ Branch 0 taken 10246317 times.
✗ Branch 1 not taken.
10246317 ArrayH::getString(arrayptr, name, 256); // What's the limit on name length?
17928
17929
1/2
✓ Branch 0 taken 10246317 times.
✗ Branch 1 not taken.
10246317 auto it = name_to_slot_index.find(name);
17930
2/2
✓ Branch 0 taken 8430579 times.
✓ Branch 1 taken 1815738 times.
10246317 if (it != name_to_slot_index.end())
17931 1815738 num = it->second + 1;
17932
17933
1/2
✓ Branch 0 taken 10246317 times.
✗ Branch 1 not taken.
10246317 set_register(sarg1, num * 10000);
17934 10246317 }
17935
17936 int32_t legacy_get_int_arr(const int32_t ptr, int32_t indx)
17937 {
17938 switch(ptr)
17939 {
17940 case INTARR_SCREEN_NPC:
17941 {
17942 current_zasm_context = "Screen->NPCs[]";
17943 if(BC::checkGuyIndex(indx) != SH::_NoError)
17944 return 0;
17945 current_zasm_context = "";
17946
17947 return guys.spr(indx)->getUID();
17948 }
17949 case INTARR_SCREEN_ITEMSPR:
17950 {
17951 current_zasm_context = "Screen->Items[]";
17952 if(BC::checkItemIndex(indx) != SH::_NoError)
17953 return 0;
17954 current_zasm_context = "";
17955
17956 return items.spr(indx)->getUID();
17957 }
17958 case INTARR_SCREEN_LWPN:
17959 {
17960 current_zasm_context = "Screen->LWeapons[]";
17961 if(BC::checkLWeaponIndex(indx) != SH::_NoError)
17962 return 0;
17963 current_zasm_context = "";
17964
17965 return Lwpns.spr(indx)->getUID();
17966 }
17967 case INTARR_SCREEN_EWPN:
17968 {
17969 current_zasm_context = "Screen->EWeapons[]";
17970 if(BC::checkEWeaponIndex(indx) != SH::_NoError)
17971 return 0;
17972 current_zasm_context = "";
17973
17974 return Ewpns.spr(indx)->getUID();
17975 }
17976 case INTARR_SCREEN_FFC:
17977 {
17978 current_zasm_context = "Screen->FFCs[]";
17979 if (auto ffc = ResolveFFCWithID(indx))
17980 {
17981 current_zasm_context = "";
17982
17983 if (ZScriptVersion::ffcRefIsSpriteId())
17984 return ffc->getUID();
17985
17986 return indx * 10000;
17987 }
17988
17989 return 0;
17990 }
17991 case INTARR_SCREEN_PORTALS:
17992 {
17993 current_zasm_context = "Screen->Portals[]";
17994 if(BC::checkBoundsOneIndexed(indx, 0, portals.Count()-1) != SH::_NoError)
17995 return 0;
17996 current_zasm_context = "";
17997
17998 return portals.spr(indx)->getUID();
17999 }
18000 case INTARR_SAVPRTL:
18001 {
18002 current_zasm_context = "Game->SavedPortals[]";
18003 if(BC::checkBoundsOneIndexed(indx, 0, game->user_portals.size()-1) != SH::_NoError)
18004 return 0;
18005 current_zasm_context = "";
18006
18007 return (indx+1)*10000;
18008 }
18009 default:
18010 {
18011 scripting_log_error_with_context("Unknown internal array '{}' read from!", ptr);
18012 return 0;
18013 }
18014 }
18015 }
18016 void legacy_set_int_arr(const int32_t ptr, int32_t indx, int32_t val)
18017 {
18018 switch(ptr)
18019 {
18020 case INTARR_SCREEN_NPC:
18021 scripting_log_error_with_context("Read-only array 'Screen->NPCs' cannot be written to!");
18022 return;
18023 case INTARR_SCREEN_ITEMSPR:
18024 scripting_log_error_with_context("Read-only array 'Screen->Items' cannot be written to!");
18025 return;
18026 case INTARR_SCREEN_LWPN:
18027 scripting_log_error_with_context("Read-only array 'Screen->LWeapons' cannot be written to!");
18028 return;
18029 case INTARR_SCREEN_EWPN:
18030 scripting_log_error_with_context("Read-only array 'Screen->EWeapons' cannot be written to!");
18031 return;
18032 case INTARR_SCREEN_FFC:
18033 scripting_log_error_with_context("Read-only array 'Screen->FFCs' cannot be written to!");
18034 return;
18035 case INTARR_SCREEN_PORTALS:
18036 scripting_log_error_with_context("Read-only array 'Screen->Portals' cannot be written to!");
18037 return;
18038 case INTARR_SAVPRTL:
18039 scripting_log_error_with_context("Read-only array 'Game->SavedPortals' cannot be written to!");
18040 return;
18041
18042 default:
18043 {
18044 scripting_log_error_with_context("Unknown internal array '{}' written to!", ptr);
18045 return;
18046 }
18047 }
18048 }
18049 int32_t legacy_sz_int_arr(const int32_t ptr)
18050 {
18051 switch(ptr)
18052 {
18053 case INTARR_SCREEN_NPC:
18054 {
18055 return guys.Count();
18056 }
18057 case INTARR_SCREEN_ITEMSPR:
18058 {
18059 return items.Count();
18060 }
18061 case INTARR_SCREEN_LWPN:
18062 {
18063 return Lwpns.Count();
18064 }
18065 case INTARR_SCREEN_EWPN:
18066 {
18067 return Ewpns.Count();
18068 }
18069 case INTARR_SCREEN_FFC:
18070 {
18071 return MAXFFCS;
18072 }
18073 case INTARR_SCREEN_PORTALS:
18074 {
18075 return portals.Count();
18076 }
18077 case INTARR_SAVPRTL:
18078 {
18079 return game->user_portals.size();
18080 }
18081 default:
18082 {
18083 scripting_log_error_with_context("Unknown internal array '{}' size read!", ptr);
18084 return -1;
18085 }
18086 }
18087 }
18088
18089 ///----------------------------------------------------------------------------------------------------//
18090 // ASM Functions //
18091 ///----------------------------------------------------------------------------------------------------//
18092
18093 65 void retstack_push(int32_t val)
18094 {
18095
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 65 times.
65 if(ri->retsp >= ret_stack->size())
18096 {
18097 scripting_log_error_with_context("RetStack over or underflow, retstack pointer = {}", ri->retsp);
18098 return;
18099 }
18100 65 ret_stack->at(ri->retsp++) = val;
18101 65 }
18102 875 optional<int32_t> retstack_pop()
18103 {
18104
2/2
✓ Branch 0 taken 810 times.
✓ Branch 1 taken 65 times.
875 if(!ri->retsp)
18105 810 return nullopt; //return from root, so, QUIT
18106 65 return ret_stack->at(--ri->retsp);
18107 875 }
18108
18109 5836 void stack_push(int32_t val)
18110 {
18111 5836 --ri->sp;
18112 5836 ri->sp &= MASK_SP;
18113 5836 SH::write_stack(ri->sp, val);
18114 5836 }
18115 25 void stack_push(int32_t val, size_t count)
18116 {
18117
2/2
✓ Branch 0 taken 173 times.
✓ Branch 1 taken 25 times.
198 for(int q = 0; q < count; ++q)
18118 {
18119 173 --ri->sp;
18120 173 ri->sp &= MASK_SP;
18121 173 SH::write_stack(ri->sp, val);
18122 173 }
18123 25 }
18124
18125 5548 int32_t stack_pop()
18126 {
18127 5548 const int32_t val = SH::read_stack(ri->sp);
18128 5548 ++ri->sp;
18129 5548 ri->sp &= MASK_SP;
18130 5548 return val;
18131 }
18132 61 int32_t stack_pop(size_t count)
18133 {
18134 61 ri->sp += count;
18135 61 ri->sp &= MASK_SP;
18136 61 const int32_t val = SH::read_stack((ri->sp-1) & MASK_SP);
18137 61 return val;
18138 }
18139
18140 ///----------------------------------------------------------------------------------------------------//
18141 //Internal (to ZScript)
18142
18143 5284 void do_set(const bool v, ScriptType whichType, const int32_t whichUID)
18144 {
18145 5284 bool allowed = true;
18146
1/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 5284 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
5284 switch(whichType) //Check for objects attempting to change own script
18147 {
18148 //case ScriptType::Global:
18149
18150 case ScriptType::FFC:
18151 if (sarg1 == FFSCRIPT)
18152 {
18153 if (auto ffc = ResolveFFC(ri->ffcref); ffc && ffc->index == whichUID)
18154 allowed = false;
18155 }
18156 break;
18157
18158 case ScriptType::Screen:
18159 if(sarg1==SCREENSCRIPT) //Only 1 screen script running at a time, no UID check needed
18160 allowed = false;
18161 break;
18162
18163 case ScriptType::Item:
18164 {
18165 bool collect = ( ( whichUID < 1 ) || (whichUID == COLLECT_SCRIPT_ITEM_ZERO) );
18166 int32_t new_UID = ( collect ) ? (( whichUID != COLLECT_SCRIPT_ITEM_ZERO ) ? (whichUID * -1) : 0) : whichUID;
18167
18168 if(collect)
18169 {
18170 if(sarg1==IDATAPSCRIPT && ri->idata==new_UID)
18171 allowed = false;
18172 }
18173 else if(sarg1==IDATASCRIPT && ri->idata==new_UID)
18174 allowed = false;
18175 break;
18176 }
18177
18178 case ScriptType::Lwpn:
18179 if(sarg1==LWPNSCRIPT && ri->lwpn==whichUID)
18180 allowed = false;
18181 break;
18182
18183 case ScriptType::NPC:
18184 if(sarg1==NPCSCRIPT && ri->guyref==whichUID)
18185 allowed = false;
18186 break;
18187
18188 case ScriptType::Ewpn:
18189 if(sarg1==EWPNSCRIPT && ri->ewpn==whichUID)
18190 allowed = false;
18191 break;
18192
18193 case ScriptType::DMap:
18194 if(sarg1==DMAPSCRIPT && ri->dmapsref==whichUID)
18195 allowed = false;
18196 break;
18197
18198 case ScriptType::ItemSprite:
18199 if(sarg1==ITEMSPRITESCRIPT && ri->itemref==whichUID)
18200 allowed = false;
18201 break;
18202 }
18203
1/2
✓ Branch 0 taken 5284 times.
✗ Branch 1 not taken.
5284 if(!allowed)
18204 {
18205 Z_scripterrlog("Script attempted to change own object's script! This has been ignored.\n");
18206 return;
18207 }
18208 5284 int32_t temp = SH::get_arg(sarg2, v);
18209 5284 set_register(sarg1, temp);
18210 5284 }
18211
18212 5836 void do_push(const bool v)
18213 {
18214 5836 const int32_t value = SH::get_arg(sarg1, v);
18215 5836 stack_push(value);
18216 5836 }
18217 3381199 void do_push_varg(const bool v)
18218 {
18219 3381199 const int32_t value = SH::get_arg(sarg1, v);
18220 3381199 zs_vargs.push_back(value);
18221 3381199 }
18222
18223 2674 void do_push_vargs(const bool v)
18224 {
18225
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2674 times.
2674 if(sarg2 < 1) return;
18226 2674 const int value = SH::get_arg(sarg1, v);
18227 2674 zs_vargs.insert(zs_vargs.end(), sarg2, value);
18228 2674 zs_vargs.push_back(value);
18229 2674 }
18230
18231 5548 void do_pop()
18232 {
18233 5548 set_register(sarg1, stack_pop());
18234 5548 }
18235
18236 void do_peek()
18237 {
18238 set_register(sarg1, SH::read_stack(ri->sp));
18239 }
18240
18241 void do_peekat(const bool v)
18242 {
18243 auto offs = SH::get_arg(sarg2,v);
18244 set_register(sarg1, SH::read_stack(ri->sp+offs));
18245 }
18246
18247 void do_writeat(const bool v1, const bool v2)
18248 {
18249 auto val = SH::get_arg(sarg1,v1);
18250 auto offs = SH::get_arg(sarg2,v2);
18251 SH::write_stack(ri->sp+offs, val);
18252 }
18253
18254 61 void do_pops() // Pop past a bunch of stuff at once. Useful for clearing the stack.
18255 {
18256 61 set_register(sarg1, stack_pop(sarg2));
18257 61 }
18258
18259 25 void do_pushs(const bool v) // Push a bunch of the same thing. Useful for filling the stack.
18260 {
18261 25 const int value = SH::get_arg(sarg1, v);
18262 25 stack_push(value, sarg2);
18263 25 }
18264
18265 50 void do_loadi()
18266 {
18267 50 const int32_t stackoffset = get_register(sarg2) / 10000;
18268 50 const int32_t value = SH::read_stack(stackoffset);
18269 50 set_register(sarg1, value);
18270 50 }
18271
18272 8 void do_storei()
18273 {
18274 8 const int32_t stackoffset = get_register(sarg2) / 10000;
18275 8 const int32_t value = get_register(sarg1);
18276 8 SH::write_stack(stackoffset, value);
18277 8 }
18278
18279 void do_loadd()
18280 {
18281 const int32_t stackoffset = (sarg2+ri->d[rSFRAME]) / 10000;
18282 const int32_t value = SH::read_stack(stackoffset);
18283 set_register(sarg1, value);
18284 }
18285
18286 6044 void do_load()
18287 {
18288 6044 const int32_t stackoffset = ri->d[rSFRAME] + sarg2;
18289 6044 const int32_t value = SH::read_stack(stackoffset);
18290 6044 set_register(sarg1, value);
18291 6044 }
18292
18293 4 static void do_load_internal_array()
18294 {
18295
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 CHECK(ZScriptVersion::gc_arrays());
18296
18297 4 auto array = find_or_create_internal_script_array({sarg2, 0});
18298
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 set_register(sarg1, array ? array->id : 0);
18299 4 }
18300
18301 22 static void do_load_internal_array_ref()
18302 {
18303
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 CHECK(ZScriptVersion::gc_arrays());
18304
18305 22 int ref = get_register(sarg3);
18306 22 auto array = find_or_create_internal_script_array({sarg2, ref});
18307
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 set_register(sarg1, array ? array->id : 0);
18308 22 }
18309
18310 void do_stored(const bool v)
18311 {
18312 const int32_t stackoffset = (sarg2+ri->d[rSFRAME]) / 10000;
18313 const int32_t value = SH::get_arg(sarg1, v);
18314 SH::write_stack(stackoffset, value);
18315 }
18316
18317 2162 void do_store(const bool v)
18318 {
18319 2162 const int32_t stackoffset = ri->d[rSFRAME] + sarg2;
18320 2162 const int32_t value = SH::get_arg(sarg1, v);
18321 2162 SH::write_stack(stackoffset, value);
18322 2162 }
18323
18324 96387 void script_store_object(uint32_t offset, uint32_t new_id)
18325 {
18326 DCHECK(offset < MAX_SCRIPT_REGISTERS);
18327
18328 // Increase, then decrease, to handle the case where a variable (holding the only reference to an object) is assigned to itself.
18329 // This is unlikely so lets not bother with a conditional that skips both ref modifications when the ids are equal.
18330 96387 uint32_t id = SH::read_stack(offset);
18331 96387 script_object_ref_inc(new_id);
18332
2/2
✓ Branch 0 taken 336 times.
✓ Branch 1 taken 96051 times.
96387 if (ri->stack_pos_is_object.contains(offset))
18333 336 script_object_ref_dec(id);
18334 else
18335 96051 ri->stack_pos_is_object.insert(offset);
18336
18337 96387 SH::write_stack(offset, new_id);
18338
18339
2/2
✓ Branch 0 taken 37661 times.
✓ Branch 1 taken 58726 times.
96387 if (util::remove_if_exists(script_object_autorelease_pool, new_id))
18340 58726 script_object_ref_dec(new_id);
18341 96387 }
18342
18343 void do_store_object(const bool v)
18344 {
18345 const int32_t stackoffset = ri->d[rSFRAME] + sarg2;
18346 const int32_t new_id = SH::get_arg(sarg1, v);
18347 script_store_object(stackoffset, new_id);
18348 }
18349
18350 473161 void script_remove_object_ref(int32_t offset)
18351 {
18352
1/2
✓ Branch 0 taken 473161 times.
✗ Branch 1 not taken.
473161 if (offset < 0 || offset >= MAX_SCRIPT_REGISTERS)
18353 {
18354 assert(false);
18355 return;
18356 }
18357
18358
2/2
✓ Branch 0 taken 347310 times.
✓ Branch 1 taken 125851 times.
473161 if (!ri->stack_pos_is_object.contains(offset))
18359 347310 return;
18360
18361 125851 uint32_t id = SH::read_stack(offset);
18362 125851 script_object_ref_dec(id);
18363 125851 ri->stack_pos_is_object.erase(offset);
18364 473161 }
18365
18366 void do_enqueue(const bool)
18367 {
18368 }
18369 void do_dequeue(const bool)
18370 {
18371 }
18372
18373 2013 void do_comp(bool v, const bool inv = false)
18374 {
18375 2013 bool v2 = false;
18376
1/2
✓ Branch 0 taken 2013 times.
✗ Branch 1 not taken.
2013 if(inv) zc_swap(v,v2);
18377 2013 ri->cmp_op2 = SH::get_arg(sarg2, v);
18378 2013 ri->cmp_op1 = SH::get_arg(sarg1, v2);
18379 2013 ri->cmp_strcache = nullopt;
18380 2013 }
18381
18382 void do_internal_strcmp()
18383 {
18384 int32_t arrayptr_a = get_register(sarg1);
18385 int32_t arrayptr_b = get_register(sarg2);
18386 string strA;
18387 string strB;
18388 ArrayH::getString(arrayptr_a, strA);
18389 ArrayH::getString(arrayptr_b, strB);
18390 ri->cmp_strcache = strcmp(strA.c_str(), strB.c_str());
18391 }
18392
18393 void do_internal_stricmp()
18394 {
18395 int32_t arrayptr_a = get_register(sarg1);
18396 int32_t arrayptr_b = get_register(sarg2);
18397 string strA;
18398 string strB;
18399 ArrayH::getString(arrayptr_a, strA);
18400 ArrayH::getString(arrayptr_b, strB);
18401 ri->cmp_strcache = stricmp(strA.c_str(), strB.c_str());
18402 }
18403
18404 5 void do_resize_array()
18405 {
18406 5 int32_t size = vbound(get_register(sarg2) / 10000, 0, 214748);
18407 5 dword ptrval = get_register(sarg1);
18408 5 ArrayManager am(ptrval);
18409 5 am.resize(size);
18410 5 }
18411
18412 void do_own_array(int arrindx, ScriptType scriptType, const int32_t UID)
18413 {
18414 ArrayManager am(arrindx);
18415
18416 if(am.internal())
18417 {
18418 Z_scripterrlog_force_trace("Cannot 'OwnArray()' an internal array '%d'\n", arrindx);
18419 return;
18420 }
18421 if(arrindx >= NUM_ZSCRIPT_ARRAYS && arrindx < NUM_ZSCRIPT_ARRAYS*2)
18422 {
18423 //ignore global arrays
18424 }
18425 else if(!am.invalid())
18426 {
18427 if(arrindx > 0 && arrindx < NUM_ZSCRIPT_ARRAYS)
18428 {
18429 arrayOwner[arrindx].reown(scriptType, UID);
18430 arrayOwner[arrindx].specOwned = true;
18431 }
18432 else if(arrindx < 0) //object array
18433 Z_scripterrlog_force_trace("Cannot 'OwnArray()' an object-based array '%d'\n", arrindx);
18434 }
18435 else Z_scripterrlog_force_trace("Tried to 'OwnArray()' an invalid array '%d'\n", arrindx);
18436 }
18437
18438 void do_destroy_array()
18439 {
18440 if (ZScriptVersion::gc_arrays())
18441 {
18442 scripting_log_error_with_context("Cannot force destroy arrays in 3.0+");
18443 return;
18444 }
18445
18446 int arrindx = get_register(sarg1);
18447
18448 ArrayManager am(arrindx);
18449
18450 if(am.internal())
18451 {
18452 Z_scripterrlog_force_trace("Cannot 'DestroyArray()' an internal array '%d'\n", arrindx);
18453 return;
18454 }
18455
18456 if(arrindx >= NUM_ZSCRIPT_ARRAYS && arrindx < NUM_ZSCRIPT_ARRAYS*2)
18457 {
18458 //ignore global arrays
18459 }
18460 else if(!am.invalid())
18461 {
18462 if(arrindx > 0 && arrindx < NUM_ZSCRIPT_ARRAYS)
18463 {
18464 arrayOwner[arrindx].clear();
18465
18466 if(localRAM[arrindx].Valid())
18467 localRAM[arrindx].Clear();
18468
18469 arrayOwner[arrindx].specCleared = true;
18470 }
18471 else if(arrindx < 0) //object array
18472 Z_scripterrlog_force_trace("Cannot 'DestroyArray()' an object-based array '%d'\n", arrindx);
18473 }
18474 else Z_scripterrlog_force_trace("Tried to 'DestroyArray()' an invalid array '%d'\n", arrindx);
18475 }
18476
18477 13691342 static dword allocatemem_old(int32_t size, bool local, ScriptType type, const uint32_t UID, script_object_type object_type)
18478 {
18479 dword ptrval;
18480
18481
1/2
✓ Branch 0 taken 13691342 times.
✗ Branch 1 not taken.
13691342 if(size < 0)
18482 {
18483 Z_scripterrlog_force_trace("Array initialized to invalid size of %d\n", size);
18484 return 0;
18485 }
18486
18487
2/2
✓ Branch 0 taken 13690548 times.
✓ Branch 1 taken 794 times.
13691342 if(local)
18488 {
18489 //localRAM[0] is used as an invalid container, so 0 can be the NULL pointer in ZScript
18490
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 446248887 times.
✓ Branch 2 taken 432558339 times.
✓ Branch 3 taken 13690548 times.
446248887 for(ptrval = 1; ptrval < NUM_ZSCRIPT_ARRAYS && localRAM[ptrval].Valid(); ptrval++) ;
18491
18492
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13690548 times.
13690548 if(ptrval >= NUM_ZSCRIPT_ARRAYS)
18493 {
18494 Z_scripterrlog_force_trace("%d local arrays already in use, no more can be allocated\n", NUM_ZSCRIPT_ARRAYS-1);
18495 ptrval = 0;
18496 DCHECK(false);
18497 }
18498 else
18499 {
18500 13690548 ZScriptArray &a = localRAM[ptrval];
18501
18502 13690548 a.Resize(size);
18503 13690548 a.setValid(true);
18504 13690548 a.setObjectType(object_type);
18505
18506
2/2
✓ Branch 0 taken 211531556 times.
✓ Branch 1 taken 13690548 times.
225222104 for(dword j = 0; j < (dword)size; j++)
18507 211531556 a[j] = 0; //initialize array
18508
18509 // Keep track of which object created the array so we know which to deallocate
18510 13690548 arrayOwner[ptrval].clear();
18511 13690548 arrayOwner[ptrval].reown(type, UID);
18512 }
18513 13690548 }
18514 else
18515 {
18516 //Globals are only allocated here at first play, otherwise in init_game
18517
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24013 times.
✓ Branch 2 taken 23219 times.
✓ Branch 3 taken 794 times.
24013 for(ptrval = 0; ptrval < game->globalRAM.size() && game->globalRAM[ptrval].Valid(); ptrval++) ;
18518
18519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 794 times.
794 if(ptrval >= game->globalRAM.size())
18520 {
18521 Z_scripterrlog_force_trace("Invalid pointer value of %u passed to global allocate\n", ptrval);
18522 ptrval = 0;
18523 //this shouldn't happen, unless people are putting ALLOCATEGMEM in their ZASM scripts where they shouldn't be
18524 DCHECK(false);
18525 return ptrval * 10000;
18526 }
18527
18528 794 ZScriptArray &a = game->globalRAM[ptrval];
18529
18530 794 a.Resize(size);
18531 794 a.setValid(true);
18532 794 a.setObjectType(object_type);
18533
18534
2/2
✓ Branch 0 taken 1124622 times.
✓ Branch 1 taken 794 times.
1125416 for(dword j = 0; j < (dword)size; j++)
18535 1124622 a[j] = 0;
18536
18537 794 ptrval += NUM_ZSCRIPT_ARRAYS; //so each pointer has a unique value
18538 }
18539
18540 13691342 return ptrval * 10000;
18541 13691342 }
18542
18543 13770371 uint32_t allocatemem(int32_t size, bool local, ScriptType type, const uint32_t UID, script_object_type object_type)
18544 {
18545
2/2
✓ Branch 0 taken 13691342 times.
✓ Branch 1 taken 79029 times.
13770371 if (!ZScriptVersion::gc_arrays())
18546 13691342 return allocatemem_old(size, local, type, UID, object_type);
18547
18548
1/2
✓ Branch 0 taken 79029 times.
✗ Branch 1 not taken.
79029 if(size < 0)
18549 {
18550 Z_scripterrlog_force_trace("Array initialized to invalid size of %d\n", size);
18551 return 0;
18552 }
18553
18554 79029 auto* array = script_arrays.create();
18555
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 79029 times.
79029 if (!array)
18556 return 0;
18557
18558 79029 ZScriptArray &a = array->arr;
18559 79029 a.Resize(size);
18560 79029 a.setValid(true);
18561 79029 a.setObjectType(object_type);
18562
18563
2/2
✓ Branch 0 taken 1113332 times.
✓ Branch 1 taken 79029 times.
1192361 for(dword j = 0; j < (dword)size; j++)
18564 1113332 a[j] = 0; //initialize array
18565
18566 79029 return array->id;
18567 13770371 }
18568
18569 13770371 void do_allocatemem(bool v, const bool local, ScriptType type, const uint32_t UID)
18570 {
18571 13770371 int32_t size = SH::get_arg(sarg2, v) / 10000;
18572
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 13770371 times.
✓ Branch 2 taken 13770371 times.
✗ Branch 3 not taken.
13770371 assert(sarg3 >= 0 && sarg3 <= (int)script_object_type::last);
18573 13770371 uint32_t id = allocatemem(size, local, type, UID, (script_object_type)sarg3);
18574 13770371 set_register(sarg1, id);
18575 13770371 }
18576
18577 13656676 void do_deallocatemem()
18578 {
18579 13656676 const int32_t ptrval = get_register(sarg1) / 10000;
18580
18581 13656676 FFScript::deallocateArray(ptrval);
18582 13656676 }
18583
18584 ///----------------------------------------------------------------------------------------------------//
18585 //Mathematical
18586
18587 2701 void do_add(const bool v)
18588 {
18589 2701 int32_t temp = SH::get_arg(sarg2, v);
18590 2701 int32_t temp2 = get_register(sarg1);
18591
18592 2701 set_register(sarg1, temp2 + temp);
18593 2701 }
18594
18595 1242 void do_sub(bool v, const bool inv = false)
18596 {
18597 1242 bool v2 = false;
18598
2/2
✓ Branch 0 taken 1236 times.
✓ Branch 1 taken 6 times.
1242 if(inv) zc_swap(v,v2);
18599
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1236 times.
1242 auto destreg = (inv ? sarg2 : sarg1);
18600 1242 int32_t temp = SH::get_arg(sarg2, v);
18601 1242 int32_t temp2 = SH::get_arg(sarg1, v2);
18602 1242 set_register(destreg, temp2 - temp);
18603 1242 }
18604
18605 564 void do_mult(const bool v)
18606 {
18607 564 int64_t temp = SH::get_arg(sarg2, v);
18608 564 int32_t temp2 = get_register(sarg1);
18609
18610 564 set_register(sarg1, int32_t((temp * temp2) / 10000));
18611 564 }
18612
18613 7 void do_div(bool v, const bool inv = false)
18614 {
18615 7 bool v2 = false;
18616
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(inv) zc_swap(v,v2);
18617
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 auto destreg = (inv ? sarg2 : sarg1);
18618 7 int64_t temp = SH::get_arg(sarg2, v);
18619 7 int64_t temp2 = SH::get_arg(sarg1, v2);
18620
18621
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(temp == 0)
18622 {
18623 scripting_log_error_with_context("Attempted to divide by zero!");
18624 set_register(destreg, int32_t(sign(temp2) * MAX_SIGNED_32));
18625 }
18626 else
18627 {
18628 7 set_register(destreg, int32_t((temp2 * 10000) / temp));
18629 }
18630 7 }
18631
18632 415 void do_mod(bool v, const bool inv = false)
18633 {
18634 415 bool v2 = false;
18635
1/2
✓ Branch 0 taken 415 times.
✗ Branch 1 not taken.
415 if(inv) zc_swap(v,v2);
18636
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 415 times.
415 auto destreg = (inv ? sarg2 : sarg1);
18637 415 int32_t temp = SH::get_arg(sarg2, v);
18638 415 int32_t temp2 = SH::get_arg(sarg1, v2);
18639
18640
1/2
✓ Branch 0 taken 415 times.
✗ Branch 1 not taken.
415 if(temp == 0)
18641 {
18642 scripting_log_error_with_context("Attempted to modulo by zero!");
18643 temp = 1;
18644 }
18645
18646 415 set_register(destreg, temp2 % temp);
18647 415 }
18648
18649 16033659 void do_trig(const bool v, const byte type)
18650 {
18651 16033659 double rangle = (SH::get_arg(sarg2, v) / 10000.0) * PI / 180.0;
18652
18653
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9550421 times.
✓ Branch 2 taken 6483138 times.
✓ Branch 3 taken 100 times.
16033659 switch(type)
18654 {
18655 case 0:
18656 9550421 set_register(sarg1, int32_t(zc::math::Sin(rangle) * 10000.0));
18657 9550421 break;
18658
18659 case 1:
18660 6483138 set_register(sarg1, int32_t(zc::math::Cos(rangle) * 10000.0));
18661 6483138 break;
18662
18663 case 2:
18664 100 set_register(sarg1, int32_t(zc::math::Tan(rangle) * 10000.0));
18665 100 break;
18666 }
18667 16033659 }
18668
18669 1480 void do_degtorad()
18670 {
18671 1480 double rangle = (SH::get_arg(sarg2, false) / 10000.0) * (PI / 180.0);
18672 1480 rangle += rangle < 0?-0.00005:0.00005;
18673
18674 1480 set_register(sarg1, int32_t(rangle * 10000.0));
18675 1480 }
18676
18677 138537 void do_radtodeg()
18678 {
18679 138537 double rangle = (SH::get_arg(sarg2, false) / 10000.0) * (180.0 / PI);
18680
18681 138537 set_register(sarg1, int32_t(rangle * 10000.0));
18682 138537 }
18683
18684 14918 void do_asin(const bool v)
18685 {
18686 14918 double temp = double(SH::get_arg(sarg2, v)) / 10000.0;
18687
18688
2/4
✓ Branch 0 taken 14918 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14918 times.
✗ Branch 3 not taken.
14918 if(temp >= -1 && temp <= 1)
18689 14918 set_register(sarg1, int32_t(asin(temp) * 10000.0));
18690 else
18691 {
18692 Z_scripterrlog("Script attempted to pass %ld into ArcSin!\n",temp);
18693 set_register(sarg1, -10000);
18694 }
18695 14918 }
18696
18697 void do_acos(const bool v)
18698 {
18699 double temp = double(SH::get_arg(sarg2, v)) / 10000.0;
18700
18701 if(temp >= -1 && temp <= 1)
18702 set_register(sarg1, int32_t(acos(temp) * 10000.0));
18703 else
18704 {
18705 Z_scripterrlog("Script attempted to pass %ld into ArcCos!\n",temp);
18706 set_register(sarg1, -10000);
18707 }
18708 }
18709
18710 5879938 void do_arctan()
18711 {
18712 5879938 double xpos = ri->d[rINDEX] / 10000.0;
18713 5879938 double ypos = ri->d[rINDEX2] / 10000.0;
18714
18715 5879938 set_register(sarg1, int32_t(atan2(ypos, xpos) * 10000.0));
18716 5879938 }
18717
18718 void do_abs(const bool v)
18719 {
18720 int32_t temp = SH::get_arg(sarg1, v);
18721 set_register(sarg1, abs(temp));
18722 }
18723
18724 969 void do_log10(const bool v)
18725 {
18726 969 double temp = double(SH::get_arg(sarg1, v)) / 10000.0;
18727
18728
1/2
✓ Branch 0 taken 969 times.
✗ Branch 1 not taken.
969 if(temp > 0)
18729 969 set_register(sarg1, int32_t(log10(temp) * 10000.0));
18730 else
18731 {
18732 Z_scripterrlog("Script tried to calculate log of %f\n", temp / 10000.0);
18733 set_register(sarg1, 0);
18734 }
18735 969 }
18736
18737 648 void do_naturallog(const bool v)
18738 {
18739 648 double temp = double(SH::get_arg(sarg1, v)) / 10000.0;
18740
18741
1/2
✓ Branch 0 taken 648 times.
✗ Branch 1 not taken.
648 if(temp > 0)
18742 648 set_register(sarg1, int32_t(log(temp) * 10000.0));
18743 else
18744 {
18745 Z_scripterrlog("Script tried to calculate ln of %f\n", temp / 10000.0);
18746 set_register(sarg1, 0);
18747 }
18748 648 }
18749
18750 void do_min(const bool v)
18751 {
18752 int32_t temp = SH::get_arg(sarg2, v);
18753 int32_t temp2 = get_register(sarg1);
18754 set_register(sarg1, zc_min(temp2, temp));
18755 }
18756
18757 void do_max(const bool v)
18758 {
18759 int32_t temp = SH::get_arg(sarg2, v);
18760 int32_t temp2 = get_register(sarg1);
18761
18762 set_register(sarg1, zc_max(temp2, temp));
18763 }
18764 void do_wrap_rad(const bool v)
18765 {
18766 ri->d[rEXP1] = wrap_zslong_rad(SH::get_arg(sarg1, v));
18767 }
18768 2397 void do_wrap_deg(const bool v)
18769 {
18770 2397 ri->d[rEXP1] = wrap_zslong_deg(SH::get_arg(sarg1, v));
18771 2397 }
18772
18773
18774 2912197 void do_rnd(const bool v)
18775 {
18776 2912197 int32_t temp = SH::get_arg(sarg2, v) / 10000;
18777
18778
2/2
✓ Branch 0 taken 2886432 times.
✓ Branch 1 taken 25765 times.
2912197 if(temp > 0)
18779 2886432 set_register(sarg1, (zc_oldrand() % temp) * 10000);
18780
2/2
✓ Branch 0 taken 2755 times.
✓ Branch 1 taken 23010 times.
25765 else if(temp < 0)
18781 2755 set_register(sarg1, (zc_oldrand() % (-temp)) * -10000);
18782 else
18783 23010 set_register(sarg1, 0); // Just return 0. (Do not log an error)
18784 2912197 }
18785
18786 void do_srnd(const bool v)
18787 {
18788 uint32_t seed = SH::get_arg(sarg1, v); //Do not `/10000`- allow the decimal portion to be used! -V
18789 zc_game_srand(seed);
18790 }
18791
18792 void do_srndrnd()
18793 {
18794 //Randomize the seed to the current system time, + or - the product of 2 random numbers.
18795 int32_t seed = time(0) + ((zc_rand() * int64_t(zc_rand())) * (zc_rand(1) ? 1 : -1));
18796 set_register(sarg1, seed);
18797 zc_game_srand(seed);
18798 }
18799
18800 //Returns the system Real-Time-Clock value for a specific type.
18801 15 void FFScript::getRTC(const bool v)
18802 {
18803 //int32_t type = get_register(sarg1) / 10000;
18804 //int32_t time = getTime(type);
18805 15 set_register(sarg1, getTime((get_register(sarg1) / 10000)) * 10000);
18806 15 }
18807
18808
18809 void do_factorial(const bool v)
18810 {
18811 int32_t temp;
18812
18813 if(v)
18814 return; //must factorial a register, not a value (why is this exactly? ~Joe123)
18815 else
18816 {
18817 temp = get_register(sarg1) / 10000;
18818
18819 if(temp < 2)
18820 {
18821 set_register(sarg1, temp >= 0 ? 10000 : 0);
18822 return;
18823 }
18824 }
18825
18826 int32_t temp2 = 1;
18827
18828 for(int32_t temp3 = temp; temp > 1; temp--)
18829 temp2 *= temp3;
18830
18831 set_register(sarg1, temp2 * 10000);
18832 }
18833
18834 6556 void do_power(bool v, const bool inv = false)
18835 {
18836 6556 bool v2 = false;
18837
1/2
✓ Branch 0 taken 6556 times.
✗ Branch 1 not taken.
6556 if(inv) zc_swap(v,v2);
18838
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6556 times.
6556 auto destreg = (inv ? sarg2 : sarg1);
18839 6556 double temp = double(SH::get_arg(sarg2, v)) / 10000.0;
18840 6556 double temp2 = double(SH::get_arg(sarg1, v2)) / 10000.0;
18841
18842
3/4
✓ Branch 0 taken 1293 times.
✓ Branch 1 taken 5263 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1293 times.
6556 if(temp == 0 && temp2 == 0)
18843 {
18844 set_register(destreg, 10000);
18845 return;
18846 }
18847
18848 6556 set_register(destreg, int32_t(pow(temp2, temp) * 10000.0));
18849 6556 }
18850
18851 void do_lpower(bool v, const bool inv = false)
18852 {
18853 bool v2 = false;
18854 if(inv) zc_swap(v,v2);
18855 auto destreg = (inv ? sarg2 : sarg1);
18856 int32_t temp = SH::get_arg(sarg2, v);
18857 int32_t temp2 = SH::get_arg(sarg1, v2);
18858
18859 if(temp == 0 && temp2 == 0)
18860 {
18861 set_register(destreg, 1);
18862 return;
18863 }
18864
18865 set_register(destreg, int32_t(pow(temp2, temp)));
18866 }
18867
18868 //could use recursion or something to avoid truncation.
18869 void do_ipower(const bool v)
18870 {
18871 double sarg2val = double(SH::get_arg(sarg2, v));
18872 if ( sarg2val == 0 )
18873 {
18874 Z_scripterrlog("Division by 0 Err: InvPower() exponent divisor cannot be 0!!\n");
18875 set_register(sarg1, 1);
18876 return;
18877 }
18878 double temp = 10000.0 / sarg2val;
18879 double temp2 = double(get_register(sarg1)) / 10000.0;
18880
18881 if(temp == 0 && temp2 == 0)
18882 {
18883 set_register(sarg1, 1);
18884 return;
18885 }
18886
18887 set_register(sarg1, int32_t(pow(temp2, temp) * 10000.0));
18888 }
18889
18890 10089782 void do_sqroot(const bool v)
18891 {
18892 10089782 double temp = double(SH::get_arg(sarg2, v)) / 10000.0;
18893
18894
2/2
✓ Branch 0 taken 422 times.
✓ Branch 1 taken 10089360 times.
10089782 if(temp < 0)
18895 {
18896 422 Z_scripterrlog("Script attempted to calculate square root of %ld!\n", temp);
18897 422 set_register(sarg1, -10000);
18898 422 return;
18899 }
18900
18901 10089360 set_register(sarg1, int32_t(sqrt(temp) * 10000.0));
18902 10089782 }
18903
18904 ///----------------------------------------------------------------------------------------------------//
18905 //Bitwise
18906
18907 1 void do_and(const bool v)
18908 {
18909 1 int32_t temp = SH::get_arg(sarg2, v) / 10000;
18910 1 int32_t temp2 = get_register(sarg1) / 10000;
18911 1 set_register(sarg1, (temp2 & temp) * 10000);
18912 1 }
18913
18914 45050 void do_and32(const bool v)
18915 {
18916 45050 int32_t temp = SH::get_arg(sarg2, v);
18917 45050 int32_t temp2 = get_register(sarg1);
18918 45050 set_register(sarg1, (temp2 & temp));
18919 45050 }
18920
18921 9428355 void do_or(const bool v)
18922 {
18923 9428355 int32_t temp = SH::get_arg(sarg2, v) / 10000;
18924 9428355 int32_t temp2 = get_register(sarg1) / 10000;
18925 9428355 set_register(sarg1, (temp2 | temp) * 10000);
18926 9428355 }
18927
18928 17 void do_or32(const bool v)
18929 {
18930 17 int32_t temp = SH::get_arg(sarg2, v);
18931 17 int32_t temp2 = get_register(sarg1);
18932 17 set_register(sarg1, (temp2 | temp));
18933 17 }
18934
18935 921308 void do_xor(const bool v)
18936 {
18937 921308 int32_t temp = SH::get_arg(sarg2, v) / 10000;
18938 921308 int32_t temp2 = get_register(sarg1) / 10000;
18939 921308 set_register(sarg1, (temp2 ^ temp) * 10000);
18940 921308 }
18941
18942 void do_xor32(const bool v)
18943 {
18944 int32_t temp = SH::get_arg(sarg2, v);
18945 int32_t temp2 = get_register(sarg1);
18946 set_register(sarg1, (temp2 ^ temp));
18947 }
18948
18949 void do_nand(const bool v)
18950 {
18951 int32_t temp = SH::get_arg(sarg2, v) / 10000;
18952 int32_t temp2 = get_register(sarg1) / 10000;
18953 set_register(sarg1, (~(temp2 & temp)) * 10000);
18954 }
18955
18956 void do_nor(const bool v)
18957 {
18958 int32_t temp = SH::get_arg(sarg2, v) / 10000;
18959 int32_t temp2 = get_register(sarg1) / 10000;
18960 set_register(sarg1, (~(temp2 | temp)) * 10000);
18961 }
18962
18963 void do_xnor(const bool v)
18964 {
18965 int32_t temp = SH::get_arg(sarg2, v) / 10000;
18966 int32_t temp2 = get_register(sarg1) / 10000;
18967 set_register(sarg1, (~(temp2 ^ temp)) * 10000);
18968 }
18969
18970 void do_not(const bool v)
18971 {
18972 int32_t temp = SH::get_arg(sarg2, v);
18973 set_register(sarg1, !temp);
18974 }
18975
18976 3709786 void do_bitwisenot(const bool v)
18977 {
18978 3709786 int32_t temp = SH::get_arg(sarg1, v) / 10000;
18979 3709786 set_register(sarg1, (~temp) * 10000);
18980 3709786 }
18981
18982 void do_bitwisenot32(const bool v)
18983 {
18984 int32_t temp = SH::get_arg(sarg1, v);
18985 set_register(sarg1, (~temp));
18986 }
18987
18988 76717145 void do_lshift(const bool v)
18989 {
18990 76717145 int32_t temp = SH::get_arg(sarg2, v) / 10000;
18991 76717145 int32_t temp2 = get_register(sarg1) / 10000;
18992 76717145 set_register(sarg1, (temp2 << temp) * 10000);
18993 76717145 }
18994
18995 22 void do_lshift32(const bool v)
18996 {
18997 22 int32_t temp = SH::get_arg(sarg2, v) / 10000;
18998 22 int32_t temp2 = get_register(sarg1);
18999 22 set_register(sarg1, (temp2 << temp));
19000 22 }
19001
19002 31394534 void do_rshift(const bool v)
19003 {
19004 31394534 int32_t temp = SH::get_arg(sarg2, v) / 10000;
19005 31394534 int32_t temp2 = get_register(sarg1) / 10000;
19006 31394534 set_register(sarg1, (temp2 >> temp) * 10000);
19007 31394534 }
19008
19009 34296 void do_rshift32(const bool v)
19010 {
19011 34296 int32_t temp = SH::get_arg(sarg2, v) / 10000;
19012 34296 int32_t temp2 = get_register(sarg1);
19013 34296 set_register(sarg1, (temp2 >> temp));
19014 34296 }
19015
19016 ///----------------------------------------------------------------------------------------------------//
19017 //Casting
19018
19019 17 void do_boolcast(const bool isFloat)
19020 {
19021
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 12 times.
17 set_register(sarg1, (get_register(sarg1) ? (isFloat ? 1 : 10000) : 0));
19022 17 }
19023
19024 ///----------------------------------------------------------------------------------------------------//
19025 //Text ptr functions
19026 6352 void do_fontheight()
19027 {
19028 6352 int32_t font = get_register(sarg1)/10000;
19029 6352 ri->d[rEXP1] = text_height(get_zc_font(font))*10000;
19030 6352 }
19031
19032 17821 void do_strwidth()
19033 {
19034 17821 int32_t strptr = get_register(sarg1);
19035 17821 int32_t font = get_register(sarg2)/10000;
19036 17821 string the_string;
19037
1/2
✓ Branch 0 taken 17821 times.
✗ Branch 1 not taken.
17821 ArrayH::getString(strptr, the_string, 512);
19038
2/4
✓ Branch 0 taken 17821 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17821 times.
✗ Branch 3 not taken.
17821 ri->d[rEXP1] = text_length(get_zc_font(font), the_string.c_str())*10000;
19039 17821 }
19040
19041 37547 void do_charwidth()
19042 {
19043 37547 char chr = get_register(sarg1)/10000;
19044 37547 int32_t font = get_register(sarg2)/10000;
19045 37547 char *cstr = new char[2];
19046 37547 cstr[0] = chr;
19047 37547 cstr[1] = '\0';
19048 37547 ri->d[rEXP1] = text_length(get_zc_font(font), cstr)*10000;
19049
1/2
✓ Branch 0 taken 37547 times.
✗ Branch 1 not taken.
37547 delete[] cstr;
19050 37547 }
19051
19052 int32_t do_msgwidth(int32_t ID)
19053 {
19054 if(BC::checkMessage(ID) != SH::_NoError)
19055 {
19056 return -1;
19057 }
19058
19059 int32_t v = text_length(get_zc_font(MsgStrings[ID].font),
19060 MsgStrings[ID].s.substr(0,MsgStrings[ID].s.find_last_not_of(' ')+1).c_str());
19061 return v;
19062 }
19063
19064 int32_t do_msgheight(int32_t ID)
19065 {
19066 if(BC::checkMessage(ID) != SH::_NoError)
19067 {
19068 return -1;
19069 }
19070 return text_height(get_zc_font(MsgStrings[ID].font));
19071 }
19072
19073 ///----------------------------------------------------------------------------------------------------//
19074 //Gameplay functions
19075
19076 107 void do_warp(bool v)
19077 {
19078 107 int32_t dmapid = SH::get_arg(sarg1, v) / 10000;
19079 107 int32_t screen = SH::get_arg(sarg2, v) / 10000;
19080
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107 times.
107 if ( ((unsigned)dmapid) >= MAXDMAPS )
19081 {
19082 Z_scripterrlog("Invalid DMap ID (%d) passed to Warp(). Aborting.\n", dmapid);
19083 return;
19084 }
19085
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107 times.
107 if ( ((unsigned)screen) >= MAPSCRS )
19086 {
19087 Z_scripterrlog("Invalid Screen Index (%d) passed to Warp(). Aborting.\n", screen);
19088 return;
19089 }
19090
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107 times.
107 if ( map_screen_index(DMaps[dmapid].map, screen + DMaps[dmapid].xoff) >= (int32_t)TheMaps.size() )
19091 {
19092 Z_scripterrlog("Invalid destination passed to Warp(). Aborting.\n");
19093 return;
19094 }
19095 107 hero_scr->sidewarpdmap[0] = dmapid;
19096 107 hero_scr->sidewarpscr[0] = screen;
19097 107 hero_scr->sidewarptype[0] = wtIWARP;
19098
1/2
✓ Branch 0 taken 107 times.
✗ Branch 1 not taken.
107 if(!get_qr(qr_OLD_HERO_WARP_RETSQUARE))
19099 {
19100 hero_scr->warpreturnc &= ~(3 << 8);
19101 set_bit(&hero_scr->sidewarpoverlayflags,0,0);
19102 }
19103 107 Hero.ffwarp = true;
19104 107 }
19105
19106 127 void do_pitwarp(bool v)
19107 {
19108 127 int32_t dmapid = SH::get_arg(sarg1, v) / 10000;
19109 127 int32_t screen = SH::get_arg(sarg2, v) / 10000;
19110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
127 if ( ((unsigned)dmapid) >= MAXDMAPS )
19111 {
19112 Z_scripterrlog("Invalid DMap ID (%d) passed to PitWarp(). Aborting.\n", dmapid);
19113 return;
19114 }
19115
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
127 if ( ((unsigned)screen) >= MAPSCRS )
19116 {
19117 Z_scripterrlog("Invalid Screen Index (%d) passed to PitWarp(). Aborting.\n", screen);
19118 return;
19119 }
19120 //Extra sanity guard.
19121
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
127 if ( map_screen_index(DMaps[dmapid].map, screen + DMaps[dmapid].xoff) >= (int32_t)TheMaps.size() )
19122 {
19123 Z_scripterrlog("Invalid destination passed to Warp(). Aborting.\n");
19124 return;
19125 }
19126 127 hero_scr->sidewarpdmap[0] = dmapid;
19127 127 hero_scr->sidewarpscr[0] = screen;
19128 127 hero_scr->sidewarptype[0] = wtIWARP;
19129
1/2
✓ Branch 0 taken 127 times.
✗ Branch 1 not taken.
127 if(!get_qr(qr_OLD_HERO_WARP_RETSQUARE))
19130 {
19131 hero_scr->warpreturnc &= ~(3 << 8);
19132 set_bit(&hero_scr->sidewarpoverlayflags,0,0);
19133 }
19134 127 Hero.ffwarp = true;
19135 127 Hero.ffpit = true;
19136 127 }
19137
19138
19139
19140 void do_showsavescreen()
19141 {
19142 bool didsaved = save_game(false, 0);
19143 set_register(sarg1, didsaved ? 10000 : 0);
19144 }
19145
19146 11096 void do_selectweapon(bool v, int32_t btn)
19147 {
19148
2/4
✓ Branch 0 taken 5436 times.
✓ Branch 1 taken 5660 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11096 switch(btn)
19149 {
19150 case 1:
19151
1/2
✓ Branch 0 taken 5660 times.
✗ Branch 1 not taken.
5660 if(!get_qr(qr_SELECTAWPN))
19152 return;
19153 5660 break;
19154 case 2:
19155 if(!get_qr(qr_SET_XBUTTON_ITEMS))
19156 return;
19157 break;
19158 case 3:
19159 if(!get_qr(qr_SET_YBUTTON_ITEMS))
19160 return;
19161 break;
19162 }
19163
19164 11096 byte dir=(byte)(SH::get_arg(sarg1, v)/10000);
19165
19166 // Selection directions don't match the normal ones...
19167
2/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 80 times.
✓ Branch 4 taken 11016 times.
11096 switch(dir)
19168 {
19169 case 0:
19170 dir=SEL_UP;
19171 break;
19172
19173 case 1:
19174 dir=SEL_DOWN;
19175 break;
19176
19177 case 2:
19178 80 dir=SEL_LEFT;
19179 80 break;
19180
19181 case 3:
19182 11016 dir=SEL_RIGHT;
19183 11016 break;
19184
19185 default:
19186 return;
19187 }
19188
19189
2/5
✗ Branch 0 not taken.
✓ Branch 1 taken 5436 times.
✓ Branch 2 taken 5660 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
11096 switch(btn)
19190 {
19191 case 0:
19192 5436 selectNextBWpn(dir);
19193 5436 break;
19194 case 1:
19195 5660 selectNextAWpn(dir);
19196 5660 break;
19197 case 2:
19198 selectNextXWpn(dir);
19199 break;
19200 case 3:
19201 selectNextYWpn(dir);
19202 break;
19203 }
19204 11096 }
19205
19206 ///----------------------------------------------------------------------------------------------------//
19207 //Screen Information
19208
19209 21032557 void do_issolid()
19210 {
19211 21032557 int32_t x = int32_t(ri->d[rINDEX] / 10000);
19212 21032557 int32_t y = int32_t(ri->d[rINDEX2] / 10000);
19213
19214 21032557 set_register(sarg1, (_walkflag(x, y, 1) ? 10000 : 0));
19215 21032557 }
19216
19217 void do_mapdataissolid()
19218 {
19219 auto result = decode_mapdata_ref(ri->mapsref);
19220 if (!result.scr)
19221 {
19222 scripting_log_error_with_context("mapdata pointer is either invalid or uninitialised");
19223 set_register(sarg1,10000);
19224 }
19225 else
19226 {
19227 int32_t x = int32_t(ri->d[rINDEX] / 10000);
19228 int32_t y = int32_t(ri->d[rINDEX2] / 10000);
19229
19230 if (result.type == mapdata_type::CanonicalScreen)
19231 {
19232 set_register(sarg1, (_walkflag(x, y, 1, result.scr) ? 10000 : 0));
19233 return;
19234 }
19235
19236 if (result.type == mapdata_type::TemporaryCurrentRegion && result.layer == 0)
19237 {
19238 set_register(sarg1, (_walkflag(x, y, 1)) ? 10000 : 0);
19239 }
19240 else if (result.type == mapdata_type::TemporaryScrollingRegion && result.layer == 0)
19241 {
19242 mapscr* s0 = GetScrollingMapscr(0, x, y);
19243 mapscr* s1 = GetScrollingMapscr(1, x, y);
19244 mapscr* s2 = GetScrollingMapscr(2, x, y);
19245 if (!s1->valid) s1 = s0;
19246 if (!s2->valid) s2 = s0;
19247 bool result = _walkflag_new(s0, s1, s2, x, y, 0_zf, true);
19248 set_register(sarg1, result ? 10000 : 0);
19249 }
19250 else
19251 {
19252 set_register(sarg1, (_walkflag(x, y, 1, result.scr) ? 10000 : 0));
19253 }
19254 }
19255 }
19256
19257 void do_mapdataissolid_layer()
19258 {
19259 auto result = decode_mapdata_ref(ri->mapsref);
19260 if (!result.scr)
19261 {
19262 scripting_log_error_with_context("mapdata pointer is either invalid or uninitialised");
19263 set_register(sarg1,10000);
19264 }
19265 else
19266 {
19267 int32_t x = int32_t(ri->d[rINDEX] / 10000);
19268 int32_t y = int32_t(ri->d[rINDEX2] / 10000);
19269 int32_t layer = int32_t(ri->d[rEXP1] / 10000);
19270 if(BC::checkBounds(layer, 0, 6) != SH::_NoError)
19271 {
19272 set_register(sarg1,10000);
19273 }
19274 else
19275 {
19276 if (result.type == mapdata_type::TemporaryCurrentRegion && result.layer == 0)
19277 {
19278 set_register(sarg1, (_walkflag_layer(x, y, 1, result.scr)) ? 10000 : 0);
19279 }
19280 else if (result.type == mapdata_type::TemporaryScrollingRegion && result.layer == 0)
19281 {
19282 set_register(sarg1, (_walkflag_layer_scrolling(x, y, 1, result.scr)) ? 10000 : 0);
19283 }
19284 else
19285 {
19286 mapscr* m = result.scr;
19287
19288 if(layer > 0)
19289 {
19290 if(m->layermap[layer] == 0)
19291 {
19292 set_register(sarg1,10000);
19293 return;
19294 }
19295
19296 m = &TheMaps[(m->layermap[layer]*MAPSCRS + m->layerscreen[layer])];
19297 }
19298
19299 set_register(sarg1, (_walkflag_layer(x, y, 1, m) ? 10000 : 0));
19300 }
19301 }
19302 }
19303 }
19304
19305 void do_issolid_layer()
19306 {
19307 int32_t x = int32_t(ri->d[rINDEX] / 10000);
19308 int32_t y = int32_t(ri->d[rINDEX2] / 10000);
19309 int32_t layer = int32_t(ri->d[rEXP1] / 10000);
19310 if(BC::checkBounds(layer, 0, 6) != SH::_NoError)
19311 {
19312 set_register(sarg1,10000);
19313 }
19314 else
19315 {
19316 set_register(sarg1, (_walkflag_layer(x, y, layer - 1, 1)) ? 10000 : 0);
19317 }
19318 }
19319
19320 257 void do_setsidewarp()
19321 {
19322 257 int32_t warp = SH::read_stack(ri->sp + 3) / 10000;
19323 257 int32_t scrn = SH::read_stack(ri->sp + 2) / 10000;
19324 257 int32_t dmap = SH::read_stack(ri->sp + 1) / 10000;
19325 257 int32_t type = SH::read_stack(ri->sp + 0) / 10000;
19326
19327 257 current_zasm_extra_context = "warp";
19328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 257 times.
257 if (BC::checkBounds(warp, -1, 3) != SH::_NoError)
19329 return;
19330
19331 257 current_zasm_extra_context = "screen";
19332
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 257 times.
257 if (BC::checkBounds(scrn, -1, 0x87) != SH::_NoError)
19333 return;
19334
19335 257 current_zasm_extra_context = "dmap";
19336
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 257 times.
257 if (BC::checkBounds(dmap, -1, MAXDMAPS - 1) != SH::_NoError)
19337 return;
19338
19339 257 current_zasm_extra_context = "type";
19340
1/2
✓ Branch 0 taken 257 times.
✗ Branch 1 not taken.
257 if (BC::checkBounds(type, -1, wtMAX - 1) != SH::_NoError)
19341 return;
19342
19343 257 current_zasm_extra_context = "";
19344
19345 257 mapscr* scr = get_scr(ri->screenref);
19346
19347
1/2
✓ Branch 0 taken 257 times.
✗ Branch 1 not taken.
257 if(scrn > -1)
19348 257 scr->sidewarpscr[warp] = scrn;
19349
19350
1/2
✓ Branch 0 taken 257 times.
✗ Branch 1 not taken.
257 if(dmap > -1)
19351 257 scr->sidewarpdmap[warp] = dmap;
19352
19353
1/2
✓ Branch 0 taken 257 times.
✗ Branch 1 not taken.
257 if(type > -1)
19354 257 scr->sidewarptype[warp] = type;
19355 257 }
19356
19357 5 void do_settilewarp()
19358 {
19359 5 int32_t warp = SH::read_stack(ri->sp + 3) / 10000;
19360 5 int32_t scrn = SH::read_stack(ri->sp + 2) / 10000;
19361 5 int32_t dmap = SH::read_stack(ri->sp + 1) / 10000;
19362 5 int32_t type = SH::read_stack(ri->sp + 0) / 10000;
19363
19364 5 current_zasm_extra_context = "warp";
19365
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (BC::checkBounds(warp, -1, 3) != SH::_NoError)
19366 return;
19367
19368 5 current_zasm_extra_context = "screen";
19369
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (BC::checkBounds(scrn, -1, 0x87) != SH::_NoError)
19370 return;
19371
19372 5 current_zasm_extra_context = "dmap";
19373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (BC::checkBounds(dmap, -1, MAXDMAPS - 1) != SH::_NoError)
19374 return;
19375
19376 5 current_zasm_extra_context = "type";
19377
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (BC::checkBounds(type, -1, wtMAX - 1) != SH::_NoError)
19378 return;
19379
19380 5 current_zasm_extra_context = "";
19381
19382 5 mapscr* scr = get_scr(ri->screenref);
19383
19384
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(scrn > -1)
19385 5 scr->tilewarpscr[warp] = scrn;
19386
19387
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(dmap > -1)
19388 5 scr->tilewarpdmap[warp] = dmap;
19389
19390
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(type > -1)
19391 5 scr->tilewarptype[warp] = type;
19392 5 }
19393
19394 354947 void do_getsidewarpdmap(const bool v)
19395 {
19396 354947 int32_t warp = SH::get_arg(sarg1, v) / 10000;
19397
19398
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 354947 times.
354947 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
19399 {
19400 set_register(sarg1, -10000);
19401 return;
19402 }
19403
19404 354947 set_register(sarg1, get_scr(ri->screenref)->sidewarpdmap[warp]*10000);
19405 354947 }
19406
19407 3 void do_getsidewarpscr(const bool v)
19408 {
19409 3 int32_t warp = SH::get_arg(sarg1, v) / 10000;
19410
19411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
19412 {
19413 set_register(sarg1, -10000);
19414 return;
19415 }
19416
19417 3 set_register(sarg1, get_scr(ri->screenref)->sidewarpscr[warp]*10000);
19418 3 }
19419
19420 void do_getsidewarptype(const bool v)
19421 {
19422 int32_t warp = SH::get_arg(sarg1, v) / 10000;
19423
19424 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
19425 {
19426 set_register(sarg1, -10000);
19427 return;
19428 }
19429
19430 set_register(sarg1, get_scr(ri->screenref)->sidewarptype[warp]*10000);
19431 }
19432
19433 354994 void do_gettilewarpdmap(const bool v)
19434 {
19435 354994 int32_t warp = SH::get_arg(sarg1, v) / 10000;
19436
19437
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 354994 times.
354994 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
19438 {
19439 set_register(sarg1, -10000);
19440 return;
19441 }
19442
19443 354994 set_register(sarg1, get_scr(ri->screenref)->tilewarpdmap[warp]*10000);
19444 354994 }
19445
19446 50 void do_gettilewarpscr(const bool v)
19447 {
19448 50 int32_t warp = SH::get_arg(sarg1, v) / 10000;
19449
19450
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
19451 {
19452 set_register(sarg1, -10000);
19453 return;
19454 }
19455
19456 50 set_register(sarg1, get_scr(ri->screenref)->tilewarpscr[warp]*10000);
19457 50 }
19458
19459 3 void do_gettilewarptype(const bool v)
19460 {
19461 3 int32_t warp = SH::get_arg(sarg1, v) / 10000;
19462
19463
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(BC::checkBounds(warp, -1, 3) != SH::_NoError)
19464 {
19465 set_register(sarg1, -10000);
19466 return;
19467 }
19468
19469 3 set_register(sarg1, get_scr(ri->screenref)->tilewarptype[warp]*10000);
19470 3 }
19471
19472 13670631 void do_layerscreen()
19473 {
19474 13670631 int32_t layer = (get_register(sarg2) / 10000) - 1;
19475
19476
3/4
✓ Branch 0 taken 13670631 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11796293 times.
✓ Branch 3 taken 1874338 times.
13670631 if(BC::checkBounds(layer, 0, 5) != SH::_NoError || get_scr(ri->screenref)->layermap[layer] == 0)
19477 1874338 set_register(sarg1, -10000);
19478 else
19479 11796293 set_register(sarg1, get_scr(ri->screenref)->layerscreen[layer] * 10000);
19480 13670631 }
19481
19482 18282859 void do_layermap()
19483 {
19484 18282859 int32_t layer = (get_register(sarg2) / 10000) - 1;
19485
19486
3/4
✓ Branch 0 taken 18282859 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15796322 times.
✓ Branch 3 taken 2486537 times.
18282859 if(BC::checkBounds(layer, 0, 5) != SH::_NoError || get_scr(ri->screenref)->layermap[layer] == 0)
19487 2486537 set_register(sarg1, -10000);
19488 else
19489 15796322 set_register(sarg1, get_scr(ri->screenref)->layermap[layer] * 10000);
19490 18282859 }
19491
19492
19493
19494 475 void do_triggersecrets(int screen)
19495 {
19496
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 475 times.
475 if (!is_in_current_region(screen))
19497 {
19498 scripting_log_error_with_context("Must be given a screen in the current region. got: {}", screen);
19499 return;
19500 }
19501
19502 475 trigger_secrets_for_screen(TriggerSource::Script, screen, false);
19503 475 }
19504
19505 void FFScript::do_graphics_getpixel()
19506 {
19507 int32_t yoffset = 0;
19508 const bool brokenOffset= ( (get_er(er_BITMAPOFFSET)!=0) || (get_qr(qr_BITMAPOFFSETFIX)!=0) );
19509 int32_t ref = (ri->d[rEXP1]);
19510
19511 BITMAP *bitty = FFCore.GetScriptBitmap(ref, screen);
19512 int32_t xpos = ri->d[rINDEX2] / 10000;
19513
19514 if(!brokenOffset && (ref-10) == -1 )
19515 {
19516 yoffset = 56; //should this be -56?
19517 }
19518 else
19519 {
19520 yoffset = 0;
19521 }
19522
19523 int32_t ypos = (ri->d[rINDEX] / 10000)+yoffset;
19524 if(!bitty)
19525 {
19526 bitty = scrollbuf;
19527 }
19528
19529 int32_t ret = getpixel(bitty, xpos, ypos); //This is a palette index value.
19530
19531 if(!get_qr(qr_BROKEN_GETPIXEL_VALUE))
19532 ret *= 10000;
19533 set_register(sarg1, ret);
19534 }
19535
19536
19537
19538
19539 ///----------------------------------------------------------------------------------------------------//
19540 //Pointer handling
19541
19542 587 bool is_valid_array(int32_t ptr)
19543 {
19544
2/2
✓ Branch 0 taken 572 times.
✓ Branch 1 taken 15 times.
587 if(!ptr) return false;
19545
19546
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 566 times.
572 if (ZScriptVersion::gc_arrays())
19547 {
19548
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (auto array = checkArray(ptr, true))
19549 6 return !array->internal_expired;
19550
19551 return false;
19552 }
19553
19554 566 ptr /= 10000;
19555
19556
2/2
✓ Branch 0 taken 565 times.
✓ Branch 1 taken 1 times.
566 if(ptr < 0) //An object array?
19557 {
19558 1 int32_t objptr = -ptr;
19559 1 auto it = objectRAM.find(objptr);
19560
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(it == objectRAM.end())
19561 return false;
19562 1 return true;
19563 }
19564
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 565 times.
565 else if(ptr >= NUM_ZSCRIPT_ARRAYS) //check global
19565 {
19566 dword gptr = ptr - NUM_ZSCRIPT_ARRAYS;
19567
19568 if(gptr > game->globalRAM.size())
19569 return false;
19570 else return game->globalRAM[gptr].Valid();
19571 }
19572 else
19573 {
19574 565 return localRAM[ptr].Valid();
19575 }
19576 587 }
19577
19578 587 void do_isvalidarray()
19579 {
19580 587 int32_t ptr = get_register(sarg1);
19581
19582 587 set_register(sarg1,is_valid_array(ptr) ? 10000 : 0);
19583 587 }
19584
19585 31487 void do_isvaliditem()
19586 {
19587 31487 int32_t IID = get_register(sarg1);
19588 //int32_t ct = items.Count();
19589
19590 //for ( int32_t j = items.Count()-1; j >= 0; --j )
19591
2/2
✓ Branch 0 taken 55605 times.
✓ Branch 1 taken 213 times.
55818 for(int32_t j = 0; j < items.Count(); j++)
19592 //for(int32_t j = 0; j < ct; j++)
19593
2/2
✓ Branch 0 taken 31274 times.
✓ Branch 1 taken 24331 times.
55605 if(items.spr(j)->getUID() == IID)
19594 {
19595 31274 set_register(sarg1, 10000);
19596 31274 return;
19597 }
19598
19599 213 set_register(sarg1, 0);
19600 31487 }
19601
19602 11754119 void do_isvalidnpc()
19603 {
19604 11754119 int32_t UID = get_register(sarg1);
19605 //for ( int32_t j = guys.Count()-1; j >= 0; --j )
19606 //int32_t ct = guys.Count();
19607
19608
2/2
✓ Branch 0 taken 34202049 times.
✓ Branch 1 taken 112140 times.
34314189 for(int32_t j = 0; j < guys.Count(); j++)
19609 //for(int32_t j = 0; j < ct; j++)
19610
2/2
✓ Branch 0 taken 11641979 times.
✓ Branch 1 taken 22560070 times.
34202049 if(guys.spr(j)->getUID() == UID)
19611 {
19612 11641979 set_register(sarg1, 10000);
19613 11641979 return;
19614 }
19615
19616 112140 set_register(sarg1, 0);
19617 11754119 }
19618
19619 1205956 void do_isvalidlwpn()
19620 {
19621 1205956 int32_t WID = get_register(sarg1);
19622 //int32_t ct = Lwpns.Count();
19623
19624 //for ( int32_t j = Lwpns.Count()-1; j >= 0; --j )
19625
2/2
✓ Branch 0 taken 3080447 times.
✓ Branch 1 taken 590865 times.
3671312 for(int32_t j = 0; j < Lwpns.Count(); j++)
19626 //for(int32_t j = 0; j < ct; j++)
19627
2/2
✓ Branch 0 taken 2465356 times.
✓ Branch 1 taken 615091 times.
3080447 if(Lwpns.spr(j)->getUID() == WID)
19628 {
19629 615091 set_register(sarg1, 10000);
19630 615091 return;
19631 }
19632
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 590865 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
590865 if(Hero.lift_wpn && Hero.lift_wpn->getUID() == WID)
19633 {
19634 set_register(sarg1, 10000);
19635 return;
19636 }
19637 590865 set_register(sarg1, 0);
19638 1205956 }
19639
19640 160009 void do_isvalidewpn()
19641 {
19642 160009 int32_t WID = get_register(sarg1);
19643
19644
2/2
✓ Branch 0 taken 961177 times.
✓ Branch 1 taken 23757 times.
984934 for(int32_t j = 0; j < Ewpns.Count(); j++)
19645
2/2
✓ Branch 0 taken 824925 times.
✓ Branch 1 taken 136252 times.
961177 if(Ewpns.spr(j)->getUID() == WID)
19646 {
19647 136252 set_register(sarg1, 10000);
19648 136252 return;
19649 }
19650 // unsure how an ewpn would be lifted, but, checking just to be safe
19651
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 23757 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
23757 if(Hero.lift_wpn && Hero.lift_wpn->getUID() == WID)
19652 {
19653 set_register(sarg1, 10000);
19654 return;
19655 }
19656 23757 set_register(sarg1, 0);
19657 160009 }
19658
19659 void do_lwpnmakeangular()
19660 {
19661 if(LwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
19662 {
19663 if (!LwpnH::getWeapon()->angular)
19664 {
19665 double vx;
19666 double vy;
19667 switch(NORMAL_DIR(LwpnH::getWeapon()->dir))
19668 {
19669 case l_up:
19670 case l_down:
19671 case left:
19672 vx = -1.0*((weapon*)s)->step;
19673 break;
19674 case r_down:
19675 case r_up:
19676 case right:
19677 vx = ((weapon*)s)->step;
19678 break;
19679
19680 default:
19681 vx = 0;
19682 break;
19683 }
19684 switch(NORMAL_DIR(LwpnH::getWeapon()->dir))
19685 {
19686 case l_up:
19687 case r_up:
19688 case up:
19689 vy = -1.0*((weapon*)s)->step;
19690 break;
19691 case l_down:
19692 case r_down:
19693 case down:
19694 vy = ((weapon*)s)->step;
19695 break;
19696
19697 default:
19698 vy = 0;
19699 break;
19700 }
19701 LwpnH::getWeapon()->angular = true;
19702 LwpnH::getWeapon()->angle=atan2(vy, vx);
19703 LwpnH::getWeapon()->step=FFCore.Distance(0, 0, vx, vy)/10000.0;
19704 LwpnH::getWeapon()->doAutoRotate();
19705 }
19706 }
19707 }
19708
19709 void do_lwpnmakedirectional()
19710 {
19711 if(LwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
19712 {
19713 if (LwpnH::getWeapon()->angular)
19714 {
19715 LwpnH::getWeapon()->dir = NORMAL_DIR(AngleToDir(WrapAngle(LwpnH::getWeapon()->angle)));
19716 LwpnH::getWeapon()->angular = false;
19717 LwpnH::getWeapon()->doAutoRotate(true);
19718 }
19719 }
19720 }
19721
19722 void do_ewpnmakeangular()
19723 {
19724 if(EwpnH::loadWeapon(ri->ewpn) == SH::_NoError)
19725 {
19726 if (!EwpnH::getWeapon()->angular)
19727 {
19728 double vx;
19729 double vy;
19730 switch(NORMAL_DIR(EwpnH::getWeapon()->dir))
19731 {
19732 case l_up:
19733 case l_down:
19734 case left:
19735 vx = -1.0*((weapon*)s)->step;
19736 break;
19737 case r_down:
19738 case r_up:
19739 case right:
19740 vx = ((weapon*)s)->step;
19741 break;
19742
19743 default:
19744 vx = 0;
19745 break;
19746 }
19747 switch(NORMAL_DIR(EwpnH::getWeapon()->dir))
19748 {
19749 case l_up:
19750 case r_up:
19751 case up:
19752 vy = -1.0*((weapon*)s)->step;
19753 break;
19754 case l_down:
19755 case r_down:
19756 case down:
19757 vy = ((weapon*)s)->step;
19758 break;
19759
19760 default:
19761 vy = 0;
19762 break;
19763 }
19764 EwpnH::getWeapon()->angular = true;
19765 EwpnH::getWeapon()->angle=atan2(vy, vx);
19766 EwpnH::getWeapon()->step=FFCore.Distance(0, 0, vx, vy)/10000.0;
19767 EwpnH::getWeapon()->doAutoRotate();
19768 }
19769 }
19770 }
19771
19772 void do_ewpnmakedirectional()
19773 {
19774 if(EwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
19775 {
19776 if (EwpnH::getWeapon()->angular)
19777 {
19778 EwpnH::getWeapon()->dir = NORMAL_DIR(AngleToDir(WrapAngle(EwpnH::getWeapon()->angle)));
19779 EwpnH::getWeapon()->angular = false;
19780 EwpnH::getWeapon()->doAutoRotate(true);
19781 }
19782 }
19783 }
19784
19785 19653 void do_lwpnusesprite(const bool v)
19786 {
19787 19653 int32_t ID = SH::get_arg(sarg1, v) / 10000;
19788
19789
1/2
✓ Branch 0 taken 19653 times.
✗ Branch 1 not taken.
19653 if(BC::checkWeaponMiscSprite(ID) != SH::_NoError)
19790 return;
19791
19792
1/2
✓ Branch 0 taken 19653 times.
✗ Branch 1 not taken.
19653 if(LwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
19793 19653 LwpnH::getWeapon()->LOADGFX(ID);
19794 19653 }
19795
19796 208946 void do_ewpnusesprite(const bool v)
19797 {
19798 208946 int32_t ID = SH::get_arg(sarg1, v) / 10000;
19799
19800
1/2
✓ Branch 0 taken 208946 times.
✗ Branch 1 not taken.
208946 if(BC::checkWeaponMiscSprite(ID) != SH::_NoError)
19801 return;
19802
19803
1/2
✓ Branch 0 taken 208946 times.
✗ Branch 1 not taken.
208946 if(EwpnH::loadWeapon(ri->ewpn) == SH::_NoError)
19804 208946 EwpnH::getWeapon()->LOADGFX(ID);
19805 208946 }
19806
19807 void do_portalusesprite()
19808 {
19809 int32_t ID = get_register(sarg1) / 10000;
19810
19811 if(BC::checkWeaponMiscSprite(ID) != SH::_NoError)
19812 return;
19813
19814 if(portal* p = checkPortal(ri->portalref))
19815 p->LOADGFX(ID);
19816 }
19817
19818 void do_clearsprites(const bool v)
19819 {
19820 int32_t spritelist = SH::get_arg(sarg1, v) / 10000;
19821
19822 if(BC::checkBounds(spritelist, 0, 5) != SH::_NoError)
19823 return;
19824
19825 switch(spritelist)
19826 {
19827 case 0:
19828 guys.clear();
19829 break;
19830
19831 case 1:
19832 items.clear();
19833 break;
19834
19835 case 2:
19836 Ewpns.clear();
19837 break;
19838
19839 case 3:
19840 Lwpns.clear();
19841 Hero.reset_hookshot();
19842 break;
19843
19844 case 4:
19845 decorations.clear();
19846 break;
19847
19848 case 5:
19849 particles.clear();
19850 break;
19851 }
19852 }
19853
19854 1452537 void do_loadlweapon(const bool v)
19855 {
19856 1452537 int32_t index = SH::get_arg(sarg1, v) / 10000;
19857
19858
2/2
✓ Branch 0 taken 16630 times.
✓ Branch 1 taken 1435907 times.
1452537 if(BC::checkLWeaponIndex(index) != SH::_NoError)
19859 16630 ri->lwpn = 0; //MAX_DWORD; //Now NULL
19860 else
19861 {
19862 1435907 ri->lwpn = Lwpns.spr(index)->getUID();
19863 // This is too trivial to log. -L
19864 }
19865 1452537 }
19866
19867 4712414 void do_loadeweapon(const bool v)
19868 {
19869 4712414 int32_t index = SH::get_arg(sarg1, v) / 10000;
19870
19871
2/2
✓ Branch 0 taken 68863 times.
✓ Branch 1 taken 4643551 times.
4712414 if(BC::checkEWeaponIndex(index) != SH::_NoError)
19872 68863 ri->ewpn = 0; //MAX_DWORD; //Now NULL
19873 else
19874 {
19875 4643551 ri->ewpn = Ewpns.spr(index)->getUID();
19876 }
19877 4712414 }
19878
19879 585769 void do_loaditem(const bool v)
19880 {
19881 585769 int32_t index = SH::get_arg(sarg1, v) / 10000;
19882
19883
2/2
✓ Branch 0 taken 298944 times.
✓ Branch 1 taken 286825 times.
585769 if(BC::checkItemIndex(index) != SH::_NoError)
19884 298944 ri->itemref = 0; //MAX_DWORD; //Now NULL
19885 else
19886 {
19887 286825 ri->itemref = items.spr(index)->getUID();
19888 }
19889 585769 }
19890
19891
19892 5620654 void do_loaditemdata(const bool v)
19893 {
19894 5620654 int32_t ID = SH::get_arg(sarg1, v) / 10000;
19895
19896 //I *think* this is the right check ~Joe
19897
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5620654 times.
5620654 if(BC::checkItemID(ID) != SH::_NoError)
19898 {
19899 ri->idata = -1; //new null value
19900 return;
19901 }
19902 5620654 ri->idata = ID;
19903 5620654 }
19904
19905 27870027 void do_loadnpc(const bool v)
19906 {
19907 27870027 int32_t index = SH::get_arg(sarg1, v) / 10000;
19908
19909
2/2
✓ Branch 0 taken 204 times.
✓ Branch 1 taken 27869823 times.
27870027 if(BC::checkGuyIndex(index) != SH::_NoError)
19910 204 ri->guyref = 0; // MAX_DWORD;
19911 else
19912 {
19913 27869823 ri->guyref = guys.spr(index)->getUID();
19914 }
19915 27870027 }
19916
19917 1173684 void FFScript::do_loaddmapdata(const bool v)
19918 {
19919 1173684 int32_t ID = SH::get_arg(sarg1, v) / 10000;
19920
19921
2/4
✓ Branch 0 taken 1173684 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1173684 times.
1173684 if ( ID < 0 || ID > 511 )
19922 {
19923 Z_scripterrlog("Invalid DMap ID passed to Game->LoadDMapData(): %d\n", ID);
19924 ri->dmapsref = MAX_DWORD;
19925 }
19926 1173684 else ri->dmapsref = ID;
19927 1173684 }
19928
19929 3 void FFScript::do_load_active_subscreendata(const bool v)
19930 {
19931 3 int32_t ID = SH::get_arg(sarg1, v) / 10000;
19932
19933
3/6
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 if(ID == -1 || (unsigned(ID) < subscreens_active.size() && unsigned(ID) < 256))
19934 {
19935 3 ri->subdataref = get_subref(ID, sstACTIVE);
19936 3 }
19937 else
19938 {
19939 Z_scripterrlog("Invalid Subscreen ID passed to Game->LoadASubData(): %d\n", ID);
19940 ri->subdataref = 0;
19941 }
19942 3 ri->d[rEXP1] = ri->subdataref;
19943 3 }
19944 void FFScript::do_load_passive_subscreendata(const bool v)
19945 {
19946 int32_t ID = SH::get_arg(sarg1, v) / 10000;
19947
19948 if(ID == -1 || (unsigned(ID) < subscreens_passive.size() && unsigned(ID) < 256))
19949 {
19950 ri->subdataref = get_subref(ID, sstPASSIVE);
19951 }
19952 else
19953 {
19954 Z_scripterrlog("Invalid Subscreen ID passed to Game->LoadPSubData(): %d\n", ID);
19955 ri->subdataref = 0;
19956 }
19957 ri->d[rEXP1] = ri->subdataref;
19958 }
19959 void FFScript::do_load_overlay_subscreendata(const bool v)
19960 {
19961 int32_t ID = SH::get_arg(sarg1, v) / 10000;
19962
19963 if(ID == -1 || (unsigned(ID) < subscreens_overlay.size() && unsigned(ID) < 256))
19964 {
19965 ri->subdataref = get_subref(ID, sstOVERLAY);
19966 }
19967 else
19968 {
19969 Z_scripterrlog("Invalid Subscreen ID passed to Game->LoadOSubData(): %d\n", ID);
19970 ri->subdataref = 0;
19971 }
19972 ri->d[rEXP1] = ri->subdataref;
19973 }
19974 3 void FFScript::do_load_subscreendata(const bool v, const bool v2)
19975 {
19976 3 int32_t ty = SH::get_arg(sarg2, v2) / 10000;
19977
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 switch(ty)
19978 {
19979 case sstACTIVE:
19980 3 do_load_active_subscreendata(v);
19981 3 break;
19982 case sstPASSIVE:
19983 do_load_passive_subscreendata(v);
19984 break;
19985 case sstOVERLAY:
19986 do_load_overlay_subscreendata(v);
19987 break;
19988 default:
19989 {
19990 Z_scripterrlog("Invalid Subscreen Type passed to ???: %d\n", ty);
19991 ri->subdataref = 0;
19992 break;
19993 }
19994 }
19995 3 ri->d[rEXP1] = ri->subdataref;
19996 3 }
19997
19998 931 void FFScript::do_loadrng()
19999 {
20000 931 auto rng = user_rngs.create();
20001
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 931 times.
931 if (!rng)
20002 {
20003 ri->d[rEXP1] = 0;
20004 return;
20005 }
20006
20007 931 int q = script_object_ids_by_type[script_object_type::rng].size() - 1;
20008 931 rng->gen = &script_rnggens[q];
20009 931 ri->rngref = rng->id;
20010 931 ri->d[rEXP1] = rng->id;
20011 931 }
20012
20013 void FFScript::do_loaddirectory()
20014 {
20015 int32_t arrayptr = get_register(sarg1);
20016 string user_path;
20017 ArrayH::getString(arrayptr, user_path, 2048);
20018
20019 std::string resolved_path;
20020 if (auto r = parse_user_path(user_path, false); !r)
20021 {
20022 scripting_log_error_with_context("Error: {}", r.error());
20023 return;
20024 } else resolved_path = r.value();
20025
20026 if (checkPath(resolved_path.c_str(), true))
20027 {
20028 ri->directoryref = user_dirs.get_free();
20029 if(!ri->directoryref) return;
20030 user_dir* d = checkDir(ri->directoryref, true);
20031 set_register(sarg1, ri->directoryref);
20032 d->setPath(resolved_path.c_str());
20033 return;
20034 }
20035
20036 scripting_log_error_with_context("Path '{}' points to a file; must point to a directory!", resolved_path);
20037 ri->directoryref = 0;
20038 set_register(sarg1, 0);
20039 }
20040
20041 void FFScript::do_loadstack()
20042 {
20043 ri->stackref = user_stacks.get_free();
20044 ri->d[rEXP1] = ri->stackref;
20045 }
20046
20047 10 void FFScript::do_loaddropset(const bool v)
20048 {
20049 10 int32_t ID = SH::get_arg(sarg1, v) / 10000;
20050
20051
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
10 if ( ID < 0 || ID > MAXITEMDROPSETS )
20052 {
20053 scripting_log_error_with_context("Invalid Dropset ID: {}", ID);
20054 ri->dropsetref = MAX_DWORD;
20055 }
20056
20057 10 else ri->dropsetref = ID;
20058 10 }
20059
20060 void FFScript::do_loadbottle(const bool v)
20061 {
20062 int32_t ID = SH::get_arg(sarg1, v) / 10000;
20063
20064 if ( ID < 1 || ID > 64 )
20065 {
20066 scripting_log_error_with_context("Invalid BottleType ID: {}", ID);
20067 ri->bottletyperef = 0;
20068 }
20069 else ri->bottletyperef = ID;
20070 }
20071
20072 void FFScript::do_loadbottleshop(const bool v)
20073 {
20074 int32_t ID = SH::get_arg(sarg1, v) / 10000;
20075
20076 if ( ID < 0 || ID > 255 )
20077 {
20078 scripting_log_error_with_context("Invalid BottleShopType ID: {}", ID);
20079 ri->bottleshopref = 0;
20080 }
20081 else ri->bottleshopref = ID+1;
20082 }
20083 137111 void FFScript::do_loadgenericdata(const bool v)
20084 {
20085 137111 int32_t ID = SH::get_arg(sarg1, v) / 10000;
20086
20087
2/4
✓ Branch 0 taken 137111 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 137111 times.
137111 if ( ID < 1 || ID > NUMSCRIPTSGENERIC )
20088 {
20089 scripting_log_error_with_context("Invalid GenericData ID: {}", ID);
20090 ri->genericdataref = 0;
20091 }
20092 137111 else ri->genericdataref = ID;
20093 137111 }
20094
20095 223 void FFScript::do_create_paldata()
20096 {
20097 223 ri->paldataref = user_paldatas.get_free();
20098 223 ri->d[rEXP1] = ri->paldataref;
20099 223 }
20100
20101 11 void FFScript::do_create_paldata_clr()
20102 {
20103 11 ri->paldataref = user_paldatas.get_free();
20104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (ri->paldataref > 0)
20105 {
20106 11 user_paldata& pd = user_paldatas[ri->paldataref];
20107 11 int32_t clri = get_register(sarg1);
20108
20109 11 RGB c = _RGB((clri >> 16) & 0xFF, (clri >> 8) & 0xFF, clri & 0xFF);
20110
20111 11 c.r = vbound(c.r, 0, scripting_max_color_val);
20112 11 c.g = vbound(c.g, 0, scripting_max_color_val);
20113 11 c.b = vbound(c.b, 0, scripting_max_color_val);
20114
20115
2/2
✓ Branch 0 taken 2640 times.
✓ Branch 1 taken 11 times.
2651 for (int32_t q = 0; q < 240; ++q)
20116 2640 pd.set_color(q, c);
20117 11 }
20118 11 ri->d[rEXP1] = ri->paldataref;
20119 11 }
20120
20121 void FFScript::do_mix_clr()
20122 {
20123 int32_t clr_start = SH::read_stack(ri->sp + 3);
20124 int32_t clr_end = SH::read_stack(ri->sp + 2);
20125 float percent = SH::read_stack(ri->sp + 1) / 10000.0;
20126 int32_t color_space = SH::read_stack(ri->sp + 0) / 10000;
20127
20128 RGB ref1c = _RGB((clr_start >> 16) & 0xFF, (clr_start >> 8) & 0xFF, clr_start & 0xFF);
20129 RGB ref2c = _RGB((clr_end >> 16) & 0xFF, (clr_end >> 8) & 0xFF, clr_end & 0xFF);
20130 RGB outputc = user_paldata::mix_color(ref1c, ref2c, percent, color_space);
20131
20132 int32_t r = vbound(outputc.r, 0, scripting_max_color_val);
20133 int32_t g = vbound(outputc.g, 0, scripting_max_color_val);
20134 int32_t b = vbound(outputc.b, 0, scripting_max_color_val);
20135
20136 ri->d[rEXP1] = (r << 16) | (g << 8) | b;
20137 }
20138
20139 void FFScript::do_create_rgb_hex()
20140 {
20141 int32_t hexrgb = get_register(sarg1);
20142
20143 int32_t r = (hexrgb >> 16) & 0xFF;
20144 int32_t g = (hexrgb >> 8) & 0xFF;
20145 int32_t b = hexrgb & 0xFF;
20146
20147 if (scripting_use_8bit_colors)
20148 {
20149 r = vbound(r, 0, 255);
20150 g = vbound(g, 0, 255);
20151 b = vbound(b, 0, 255);
20152 }
20153 else
20154 {
20155 r = vbound(r / 4, 0, 63);
20156 g = vbound(g / 4, 0, 63);
20157 b = vbound(b / 4, 0, 63);
20158 }
20159
20160 ri->d[rEXP1] = (r << 16) | (g << 8) | b;
20161 }
20162
20163 11 void FFScript::do_create_rgb()
20164 {
20165 11 int32_t r = SH::read_stack(ri->sp + 2) / 10000;
20166 11 int32_t g = SH::read_stack(ri->sp + 1) / 10000;
20167 11 int32_t b = SH::read_stack(ri->sp + 0) / 10000;
20168
20169 11 int max_value = scripting_max_color_val;
20170
4/6
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
11 if (unsigned(r) > max_value || unsigned(g) > max_value || unsigned(b) > max_value)
20171 {
20172 1 scripting_log_error_with_context("R/G/B values should range from 0-{}, got: {} {} {}", max_value, r, g, b);
20173 1 }
20174
20175 11 r = vbound(r, 0, max_value);
20176 11 g = vbound(g, 0, max_value);
20177 11 b = vbound(b, 0, max_value);
20178
20179 11 ri->d[rEXP1] = (r << 16) | (g << 8) | b;
20180 11 }
20181
20182 void FFScript::do_convert_from_rgb()
20183 {
20184 int32_t buf = SH::read_stack(ri->sp + 2) / 10000;
20185 int32_t clri = SH::read_stack(ri->sp + 1);
20186 int32_t color_space = SH::read_stack(ri->sp + 0) / 10000;
20187
20188 ArrayManager am(buf);
20189 if (am.invalid()) return;
20190 int32_t zscript_array_size = am.size();
20191 int32_t target_size;
20192
20193 switch (color_space)
20194 {
20195 case user_paldata::CSPACE_CMYK:
20196 target_size = 4;
20197 break;
20198 default:
20199 target_size = 3;
20200 }
20201
20202 if (zscript_array_size < target_size)
20203 {
20204 scripting_log_error_with_context("Array not large enough. Should be at least size {}", target_size);
20205 return;
20206 }
20207
20208 RGB c = _RGB((clri >> 16) & 0xFF, (clri >> 8) & 0xFF, clri & 0xFF);
20209 double convert[4];
20210 user_paldata::RGBTo(c, convert, color_space);
20211
20212 for (int32_t q = 0; q < target_size; ++q)
20213 {
20214 am.set(q, int32_t(convert[q]*10000));
20215 }
20216
20217 return;
20218 }
20219
20220 void FFScript::do_convert_to_rgb()
20221 {
20222 int32_t buf = SH::read_stack(ri->sp + 1) / 10000;
20223 int32_t color_space = SH::read_stack(ri->sp + 0) / 10000;
20224
20225 ArrayManager am(buf);
20226 if (am.invalid()) return;
20227 int32_t zscript_array_size = am.size();
20228 int32_t target_size;
20229
20230 switch (color_space)
20231 {
20232 case user_paldata::CSPACE_CMYK:
20233 target_size = 4;
20234 break;
20235 default:
20236 target_size = 3;
20237 }
20238
20239 if (zscript_array_size < target_size)
20240 {
20241 scripting_log_error_with_context("Array not large enough. Should be at least size {}", target_size);
20242 return;
20243 }
20244
20245 double convert[4];
20246 for (int32_t q = 0; q < target_size; ++q)
20247 {
20248 convert[q] = am.get(q) / 10000.0;
20249 }
20250 RGB c = user_paldata::RGBFrom(convert, color_space);
20251
20252 ri->d[rEXP1] = (c.r << 16) | (c.g << 8) | c.b;
20253 }
20254
20255 24 void FFScript::do_paldata_load_level()
20256 {
20257
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (user_paldata* pd = checkPalData(ri->paldataref))
20258 {
20259 24 int32_t lvl = get_register(sarg1) / 10000;
20260 //Load CSets 2-4
20261 24 pd->load_cset(2, lvl * pdLEVEL + poLEVEL + 0);
20262 24 pd->load_cset(3, lvl * pdLEVEL + poLEVEL + 1);
20263 24 pd->load_cset(4, lvl * pdLEVEL + poLEVEL + 2);
20264 //Load CSet 9
20265 24 pd->load_cset(9, lvl * pdLEVEL + poLEVEL + 3);
20266 //Load 1, 5, 7, 8
20267 24 pd->load_cset(1, lvl * pdLEVEL + poNEWCSETS);
20268 24 pd->load_cset(5, lvl * pdLEVEL + poNEWCSETS + 1);
20269 24 pd->load_cset(7, lvl * pdLEVEL + poNEWCSETS + 2);
20270 24 pd->load_cset(8, lvl * pdLEVEL + poNEWCSETS + 3);
20271 24 }
20272 24 return;
20273 }
20274
20275 87 void FFScript::do_paldata_load_sprite()
20276 {
20277
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 87 times.
87 if (user_paldata* pd = checkPalData(ri->paldataref))
20278 {
20279 87 int32_t page = get_register(sarg1) / 10000;
20280
20281 87 int32_t pageoffset = 0;
20282
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 87 times.
✗ Branch 2 not taken.
87 switch (page)
20283 {
20284 87 case 0: pageoffset += 0; break;
20285 case 1: pageoffset += 15; break;
20286 default:
20287 scripting_log_error_with_context("Invalid page: {}. Valid pages are 0 or 1. Aborting.", page);
20288 return;
20289 }
20290
2/2
✓ Branch 0 taken 1305 times.
✓ Branch 1 taken 87 times.
1392 for (int32_t q = 0; q < 15; ++q)
20291 {
20292 1305 pd->load_cset(q, poSPRITE255 + pageoffset + q);
20293 1305 }
20294 87 }
20295 87 return;
20296 87 }
20297
20298 92 void FFScript::do_paldata_load_main()
20299 {
20300
1/2
✓ Branch 0 taken 92 times.
✗ Branch 1 not taken.
92 if (user_paldata* pd = checkPalData(ri->paldataref))
20301 {
20302
2/2
✓ Branch 0 taken 1472 times.
✓ Branch 1 taken 92 times.
1564 for (int32_t q = 0; q <= 15; ++q)
20303 {
20304 1472 pd->load_cset_main(q);
20305 1472 }
20306 92 }
20307 92 return;
20308 }
20309
20310 void FFScript::do_paldata_load_cycle()
20311 {
20312 if (user_paldata* pd = checkPalData(ri->paldataref))
20313 {
20314 int32_t lvl = get_register(sarg1) / 10000;
20315 for (int32_t q = 4; q <= 12; ++q)
20316 {
20317 pd->load_cset(q, lvl * pdLEVEL + poLEVEL + q);
20318 }
20319 }
20320 return;
20321 }
20322
20323 void FFScript::do_paldata_load_bitmap()
20324 {
20325 if (user_paldata* pd = checkPalData(ri->paldataref))
20326 {
20327 int32_t pathptr = get_register(sarg1);
20328 string user_path, str;
20329 ArrayH::getString(pathptr, user_path, 256);
20330
20331 if (get_qr(qr_BITMAP_AND_FILESYSTEM_PATHS_ALWAYS_RELATIVE))
20332 {
20333 if (auto r = parse_user_path(user_path, true); !r)
20334 {
20335 scripting_log_error_with_context("Error: {}", r.error());
20336 return;
20337 } else str = r.value();
20338 }
20339 else
20340 {
20341 str = user_path;
20342 regulate_path(str);
20343 }
20344
20345 if (str.empty())
20346 {
20347 al_trace("String pointer is null! Internal error. \n");
20348 return;
20349 }
20350
20351 PALETTE tempPal;
20352 get_palette(tempPal);
20353 if (checkPath(str.c_str(), false))
20354 {
20355 BITMAP* bmp = load_bitmap(str.c_str(), tempPal);
20356 if (!bmp)
20357 {
20358 Z_scripterrlog("LoadBitmapPalette() failed to load image file %s.\n", str.c_str());
20359 }
20360 else
20361 {
20362 for (int32_t q = 0; q < PALDATA_NUM_COLORS; ++q)
20363 {
20364 pd->colors[q] = tempPal[q];
20365 set_bit(pd->colors_used, q, true);
20366 }
20367 }
20368 destroy_bitmap(bmp);
20369 }
20370 else
20371 {
20372 Z_scripterrlog("Failed to load image file: %s. File not found.\n", str.c_str());
20373 }
20374 }
20375 return;
20376 }
20377
20378 370 void FFScript::do_paldata_write_level()
20379 {
20380
1/2
✓ Branch 0 taken 370 times.
✗ Branch 1 not taken.
370 if (user_paldata* pd = checkPalData(ri->paldataref))
20381 {
20382 370 int32_t lvl = get_register(sarg1) / 10000;
20383 370 bool changed = false;
20384 //Write CSets 2-4
20385
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(2, lvl * pdLEVEL + poLEVEL + 0))
20386 {
20387 360 pd->write_cset(2, lvl * pdLEVEL + poLEVEL + 0);
20388 360 changed = true;
20389 360 }
20390
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(3, lvl * pdLEVEL + poLEVEL + 1))
20391 {
20392 360 pd->write_cset(3, lvl * pdLEVEL + poLEVEL + 1);
20393 360 changed = true;
20394 360 }
20395
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(4, lvl * pdLEVEL + poLEVEL + 2))
20396 {
20397 360 pd->write_cset(4, lvl * pdLEVEL + poLEVEL + 2);
20398 360 changed = true;
20399 360 }
20400 //Write CSet 9
20401
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(9, lvl * pdLEVEL + poLEVEL + 3))
20402 {
20403 360 pd->write_cset(9, lvl * pdLEVEL + poLEVEL + 3);
20404 360 changed = true;
20405 360 }
20406 //Write 1, 5, 7, 8
20407
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(1, lvl * pdLEVEL + poNEWCSETS + 0))
20408 {
20409 360 pd->write_cset(1, lvl * pdLEVEL + poNEWCSETS + 0);
20410 360 changed = true;
20411 360 }
20412
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(5, lvl * pdLEVEL + poNEWCSETS + 1))
20413 {
20414 360 pd->write_cset(5, lvl * pdLEVEL + poNEWCSETS + 1);
20415 360 changed = true;
20416 360 }
20417
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(7, lvl * pdLEVEL + poNEWCSETS + 2))
20418 {
20419 360 pd->write_cset(7, lvl * pdLEVEL + poNEWCSETS + 2);
20420 360 changed = true;
20421 360 }
20422
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 360 times.
370 if (pd->check_cset(8, lvl * pdLEVEL + poNEWCSETS + 3))
20423 {
20424 360 pd->write_cset(8, lvl * pdLEVEL + poNEWCSETS + 3);
20425 360 changed = true;
20426 360 }
20427
20428
4/4
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 350 times.
370 if (changed && DMaps[cur_dmap].color == lvl)
20429 {
20430 350 loadlvlpal(lvl);
20431 350 currcset = lvl;
20432
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 350 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
350 if (darkroom && !get_qr(qr_NEW_DARKROOM))
20433 {
20434 if (get_qr(qr_FADE))
20435 {
20436 interpolatedfade();
20437 }
20438 else
20439 {
20440 loadfadepal((DMaps[cur_dmap].color) * pdLEVEL + poFADE3);
20441 }
20442 }
20443 350 }
20444 370 }
20445 370 return;
20446 }
20447
20448 void FFScript::do_paldata_write_levelcset()
20449 {
20450 if (user_paldata* pd = checkPalData(ri->paldataref))
20451 {
20452 int32_t lvl = get_register(sarg1) / 10000;
20453 int32_t cs = get_register(sarg2) / 10000;
20454
20455 bool changed = false;
20456
20457 switch (cs)
20458 {
20459 case 1:
20460 if (pd->check_cset(1, lvl * pdLEVEL + poNEWCSETS + 0))
20461 {
20462 pd->write_cset(1, lvl * pdLEVEL + poNEWCSETS + 0);
20463 changed = true;
20464 }
20465 break;
20466 case 2:
20467 if (pd->check_cset(2, lvl * pdLEVEL + poLEVEL + 0))
20468 {
20469 pd->write_cset(2, lvl * pdLEVEL + poLEVEL + 0);
20470 changed = true;
20471 }
20472 break;
20473 case 3:
20474 if (pd->check_cset(3, lvl * pdLEVEL + poLEVEL + 1))
20475 {
20476 pd->write_cset(3, lvl * pdLEVEL + poLEVEL + 1);
20477 changed = true;
20478 }
20479 break;
20480 case 4:
20481 if (pd->check_cset(4, lvl * pdLEVEL + poLEVEL + 2))
20482 {
20483 pd->write_cset(4, lvl * pdLEVEL + poLEVEL + 2);
20484 changed = true;
20485 }
20486 break;
20487 case 5:
20488 if (pd->check_cset(5, lvl * pdLEVEL + poNEWCSETS + 1))
20489 {
20490 pd->write_cset(5, lvl * pdLEVEL + poNEWCSETS + 1);
20491 changed = true;
20492 }
20493 break;
20494 case 7:
20495 if (pd->check_cset(7, lvl * pdLEVEL + poNEWCSETS + 2))
20496 {
20497 pd->write_cset(7, lvl * pdLEVEL + poNEWCSETS + 2);
20498 changed = true;
20499 }
20500 break;
20501 case 8:
20502 if (pd->check_cset(8, lvl * pdLEVEL + poNEWCSETS + 3))
20503 {
20504 pd->write_cset(8, lvl * pdLEVEL + poNEWCSETS + 3);
20505 changed = true;
20506 }
20507 break;
20508 case 9:
20509 if (pd->check_cset(9, lvl * pdLEVEL + poLEVEL + 3))
20510 {
20511 pd->write_cset(9, lvl * pdLEVEL + poLEVEL + 3);
20512 changed = true;
20513 }
20514 break;
20515 default:
20516 Z_scripterrlog("Invalid CSet (%d) passed to 'paldata->WriteLevelCSet()'. Level palettes can use CSets 1, 2, 3, 4, 5, 7, 8, 9.\n");
20517 return;
20518 }
20519
20520 if (changed && DMaps[cur_dmap].color == lvl)
20521 {
20522 loadlvlpal(lvl);
20523 if (darkroom && !get_qr(qr_NEW_DARKROOM))
20524 {
20525 if (get_qr(qr_FADE))
20526 {
20527 interpolatedfade();
20528 }
20529 else
20530 {
20531 loadfadepal((DMaps[cur_dmap].color) * pdLEVEL + poFADE3);
20532 }
20533 }
20534 currcset = lvl;
20535 }
20536 }
20537 }
20538
20539 31 void FFScript::do_paldata_write_sprite()
20540 {
20541
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
31 if (user_paldata* pd = checkPalData(ri->paldataref))
20542 {
20543 31 int32_t page = get_register(sarg1) / 10000;
20544
20545 31 int32_t pageoffset = 0;
20546
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
31 switch (page)
20547 {
20548 31 case 0: pageoffset += 0; break;
20549 case 1: pageoffset += 15; break;
20550 default:
20551 Z_scripterrlog("Invalid page (%d) passed to paldata->WriteSpritePalette(). Valid pages are 0 or 1. Aborting.\n", page);
20552 return;
20553 }
20554 31 bool changed6 = false;
20555 31 bool changed14 = false;
20556
2/2
✓ Branch 0 taken 465 times.
✓ Branch 1 taken 31 times.
496 for (int32_t q = 0; q < 15; ++q)
20557 {
20558
2/2
✓ Branch 0 taken 440 times.
✓ Branch 1 taken 25 times.
465 if (pd->check_cset(q, poSPRITE255 + pageoffset + q))
20559 {
20560 25 pd->write_cset(q, poSPRITE255 + pageoffset + q);
20561
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 if (pageoffset + q == currspal6)
20562 {
20563 changed6 = true;
20564 }
20565
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 if (pageoffset + q == currspal14)
20566 {
20567 changed14 = true;
20568 }
20569 25 }
20570 465 }
20571
20572 //If either sprite palette has been changed, update the main palette
20573
2/4
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31 times.
31 if (changed6 || changed14)
20574 {
20575 if (changed6)
20576 {
20577 loadpalset(6, poSPRITE255 + currspal6, false);
20578 }
20579 if (changed14)
20580 {
20581 loadpalset(14, poSPRITE255 + currspal14, false);
20582 }
20583
20584 if (isUserTinted()) {
20585 restoreTint();
20586 }
20587 }
20588 31 }
20589 31 return;
20590 31 }
20591
20592 void FFScript::do_paldata_write_spritecset()
20593 {
20594 if (user_paldata* pd = checkPalData(ri->paldataref))
20595 {
20596 int32_t page = get_register(sarg1) / 10000;
20597 int32_t cs = get_register(sarg2) / 10000;
20598
20599 int32_t pageoffset = 0;
20600 switch (page)
20601 {
20602 case 0: pageoffset += 0; break;
20603 case 1: pageoffset += 15; break;
20604 default:
20605 Z_scripterrlog("Invalid page (%d) passed to paldata->WriteSpriteCSet(). Valid pages are 0 or 1. Aborting.\n", page);
20606 return;
20607 }
20608 bool changed6 = false;
20609 bool changed14 = false;
20610 if (unsigned(cs) > 15)
20611 {
20612 Z_scripterrlog("Invalid CSet (%d) passed to paldata->WriteSpriteCSet(). Valid CSets are 0-15. Aborting.\n", cs);
20613 return;
20614 }
20615 if (pd->check_cset(cs, poSPRITE255 + pageoffset + cs))
20616 {
20617 pd->write_cset(cs, poSPRITE255 + pageoffset + cs);
20618 if (pageoffset + cs == currspal6)
20619 {
20620 changed6 = true;
20621 }
20622 if (pageoffset + cs == currspal14)
20623 {
20624 changed14 = true;
20625 }
20626 }
20627
20628 //If either sprite palette has been changed, update the main palette
20629 if (changed6 || changed14)
20630 {
20631 if (changed6)
20632 {
20633 loadpalset(6, poSPRITE255 + currspal6, false);
20634 }
20635 if (changed14)
20636 {
20637 loadpalset(14, poSPRITE255 + currspal14, false);
20638 }
20639
20640 if (isUserTinted()) {
20641 restoreTint();
20642 }
20643 }
20644 }
20645 return;
20646 }
20647
20648 1064 void FFScript::do_paldata_write_main()
20649 {
20650
1/2
✓ Branch 0 taken 1064 times.
✗ Branch 1 not taken.
1064 if (user_paldata* pd = checkPalData(ri->paldataref))
20651 {
20652 1064 bool changed = false;
20653
2/2
✓ Branch 0 taken 17024 times.
✓ Branch 1 taken 1064 times.
18088 for (int32_t q = 0; q <= 15; ++q)
20654 {
20655
2/2
✓ Branch 0 taken 11363 times.
✓ Branch 1 taken 5661 times.
17024 if (pd->check_cset_main(q))
20656 {
20657 5661 pd->write_cset_main(q);
20658 5661 changed = true;
20659 5661 }
20660 17024 }
20661
20662
2/2
✓ Branch 0 taken 332 times.
✓ Branch 1 taken 732 times.
1064 if (changed)
20663 {
20664 732 refreshpal = true;
20665 732 }
20666 1064 }
20667 1064 return;
20668 }
20669
20670 130 void FFScript::do_paldata_write_maincset()
20671 {
20672
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
130 if (user_paldata* pd = checkPalData(ri->paldataref))
20673 {
20674 130 int32_t cs = get_register(sarg1) / 10000;
20675
20676 130 bool changed = false;
20677
20678
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (unsigned(cs) < 16)
20679 {
20680
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (pd->check_cset_main(cs))
20681 {
20682 130 pd->write_cset_main(cs);
20683 130 changed = true;
20684 130 }
20685 130 }
20686 else
20687 {
20688 Z_scripterrlog("Invalid CSet (%d) passed to 'paldata->WriteMainCSet()'. Valid csets are 0-15. Aborting.\n");
20689 return;
20690 }
20691
20692
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (changed)
20693 {
20694 130 refreshpal = true;
20695 130 }
20696 130 }
20697 130 }
20698
20699 void FFScript::do_paldata_write_cycle()
20700 {
20701 if (user_paldata* pd = checkPalData(ri->paldataref))
20702 {
20703 int32_t lvl = get_register(sarg1) / 10000;
20704 for (int32_t q = 4; q <= 12; ++q)
20705 {
20706 if (pd->check_cset(q, lvl * pdLEVEL + poLEVEL + q))
20707 {
20708 pd->write_cset(q, lvl * pdLEVEL + poLEVEL + q);
20709 }
20710 }
20711 }
20712 return;
20713 }
20714
20715 void FFScript::do_paldata_write_cyclecset()
20716 {
20717 if (user_paldata* pd = checkPalData(ri->paldataref))
20718 {
20719 int32_t lvl = get_register(sarg1) / 10000;
20720 int32_t cs = get_register(sarg2) / 10000;
20721
20722 bool changed = false;
20723
20724 switch (cs)
20725 {
20726 case 4:
20727 case 5:
20728 case 6:
20729 case 7:
20730 case 8:
20731 case 9:
20732 case 10:
20733 case 11:
20734 case 12:
20735 if (pd->check_cset(cs, lvl * pdLEVEL + poLEVEL + cs))
20736 {
20737 pd->write_cset(cs, lvl * pdLEVEL + poLEVEL + cs);
20738 changed = true;
20739 }
20740 break;
20741 default:
20742 Z_scripterrlog("Invalid CSet (%d) passed to 'paldata->WriteCycleCSet()'. Cycle palettes use CSets 4-12.\n");
20743 return;
20744 }
20745
20746 if (changed && DMaps[cur_dmap].color == lvl)
20747 {
20748 loadlvlpal(lvl);
20749 currcset = lvl;
20750 }
20751 }
20752 }
20753
20754 void FFScript::do_paldata_colorvalid()
20755 {
20756 if (user_paldata* pd = checkPalData(ri->paldataref))
20757 {
20758 int32_t ind = get_register(sarg1) / 10000;
20759 if (unsigned(ind) >= PALDATA_NUM_COLORS)
20760 {
20761 Z_scripterrlog("Invalid color index (%d) passed to paldata->ColorValid(). Valid indices are 0-255.\n", ind);
20762 set_register(sarg1, 0);
20763 return;
20764 }
20765
20766 if (get_bit(pd->colors_used, ind))
20767 {
20768 set_register(sarg1, 10000);
20769 }
20770 else
20771 {
20772 set_register(sarg1, 0);
20773 }
20774 }
20775 }
20776
20777 void FFScript::do_paldata_clearcolor()
20778 {
20779 if (user_paldata* pd = checkPalData(ri->paldataref))
20780 {
20781 int32_t ind = get_register(sarg1) / 10000;
20782 if (unsigned(ind) >= PALDATA_NUM_COLORS)
20783 {
20784 Z_scripterrlog("Invalid color index (%d) passed to paldata->ClearColor(). Valid indices are 0-255. Aborting.\n", ind);
20785 return;
20786 }
20787 set_bit(pd->colors_used, ind, false);
20788 }
20789 }
20790
20791 void FFScript::do_paldata_clearcset()
20792 {
20793 if (user_paldata* pd = checkPalData(ri->paldataref))
20794 {
20795 int32_t cs = get_register(sarg1) / 10000;
20796 if (unsigned(cs) > 15)
20797 {
20798 Z_scripterrlog("Invalid cset (%d) passed to paldata->ClearCSet(). Valid csets are 0-15. Aborting.\n", cs);
20799 return;
20800 }
20801 for (int32_t q = 0; q < 16; ++q)
20802 {
20803 set_bit(pd->colors_used, CSET(cs) + q, false);
20804 }
20805 }
20806 }
20807
20808 int32_t FFScript::do_paldata_getrgb(user_paldata* pd, int32_t index, int32_t c)
20809 {
20810 if (pd)
20811 {
20812 int32_t ind = index;
20813 if (unsigned(ind) >= PALDATA_NUM_COLORS)
20814 {
20815 scripting_log_error_with_context("Invalid color index ({}). Valid indices are 0-255.", ind);
20816 return -10000;
20817 }
20818 if (!get_bit(pd->colors_used, ind))
20819 {
20820 scripting_log_error_with_context("Tried to access unused color {}.", ind);
20821 return -10000;
20822 }
20823 switch (c)
20824 {
20825 case 0:
20826 return pd->colors[ind].r * 10000;
20827 case 1:
20828 return pd->colors[ind].g * 10000;
20829 case 2:
20830 return pd->colors[ind].b * 10000;
20831 }
20832 }
20833
20834 return -10000;
20835 }
20836
20837 void FFScript::do_paldata_setrgb(user_paldata* pd, int32_t index, int32_t val, int32_t c)
20838 {
20839 if (pd)
20840 {
20841 int32_t ind = index;
20842 if (unsigned(ind) >= PALDATA_NUM_COLORS)
20843 {
20844 scripting_log_error_with_context("Invalid color index ({}). Valid indices are 0-255. Aborting.", ind);
20845 return;
20846 }
20847 if (unsigned(val) > scripting_max_color_val)
20848 {
20849 scripting_log_error_with_context("RGB value({}) is out of range. RGB values range from 0 - {}.", val, scripting_max_color_val);
20850 val = vbound(val, 0, scripting_max_color_val);
20851 }
20852 if (!get_bit(pd->colors_used, ind))
20853 {
20854 scripting_log_error_with_context("Tried to access unused color {}.", ind);
20855 return;
20856 }
20857 switch (c)
20858 {
20859 case 0:
20860 pd->colors[ind].r = val;
20861 break;
20862 case 1:
20863 pd->colors[ind].g = val;
20864 break;
20865 case 2:
20866 pd->colors[ind].b = val;
20867 break;
20868 }
20869 }
20870 }
20871
20872 450 void FFScript::do_paldata_mix()
20873 {
20874 450 int32_t ref = SH::read_stack(ri->sp + 4);
20875
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
450 if (user_paldata* pd = checkPalData(ref))
20876 {
20877 450 int32_t ref1 = SH::read_stack(ri->sp + 3);
20878 450 int32_t ref2 = SH::read_stack(ri->sp + 2);
20879 450 double percent = SH::read_stack(ri->sp + 1)/10000.0;
20880 450 int32_t color_space = SH::read_stack(ri->sp + 0)/10000;
20881
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
450 if (user_paldata* pd_start = checkPalData(ref1))
20882 {
20883
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
450 if (user_paldata* pd_end = checkPalData(ref2))
20884 {
20885 450 pd->mix(pd_start, pd_end, percent, color_space);
20886 450 }
20887 450 }
20888 450 }
20889 450 }
20890
20891 4781 void FFScript::do_paldata_mixcset()
20892 {
20893 4781 int32_t ref = SH::read_stack(ri->sp + 5);
20894
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4781 times.
4781 if (user_paldata* pd = checkPalData(ref))
20895 {
20896 4781 int32_t ref1 = SH::read_stack(ri->sp + 4);
20897 4781 int32_t ref2 = SH::read_stack(ri->sp + 3);
20898 4781 int32_t cset = SH::read_stack(ri->sp + 2) / 10000;
20899 4781 double percent = SH::read_stack(ri->sp + 1) / 10000.0;
20900 4781 int32_t color_space = SH::read_stack(ri->sp + 0) / 10000;
20901
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4781 times.
4781 if (user_paldata* pd_start = checkPalData(ref1))
20902 {
20903
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4781 times.
4781 if (user_paldata* pd_end = checkPalData(ref2))
20904 {
20905
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4781 times.
4781 if (unsigned(cset) > 15)
20906 {
20907 Z_scripterrlog("CSet passed to 'paldata->MixCSet()' out of range. Valid CSets are 0-15\n");
20908 return;
20909 }
20910 4781 pd->mix(pd_start, pd_end, percent, color_space, CSET(cset), CSET(cset) + 16);
20911 4781 }
20912 4781 }
20913 4781 }
20914 4781 }
20915
20916 void FFScript::do_paldata_copy()
20917 {
20918 if (user_paldata* pd = checkPalData(ri->paldataref))
20919 {
20920 int32_t ref_dest = get_register(sarg1);
20921 if (user_paldata* pd_dest = checkPalData(ref_dest))
20922 {
20923 for (int32_t q = 0; q < PALDATA_NUM_COLORS; ++q)
20924 {
20925 pd_dest->colors[q] = pd->colors[q];
20926 }
20927 for (int32_t q = 0; q < PALDATA_BITSTREAM_SIZE; ++q)
20928 {
20929 pd_dest->colors_used[q] = pd->colors_used[q];
20930 }
20931 }
20932 }
20933 }
20934
20935 112 void FFScript::do_paldata_copycset()
20936 {
20937 112 ri->paldataref = SH::read_stack(ri->sp + 3);
20938
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
112 if (user_paldata* pd = checkPalData(ri->paldataref))
20939 {
20940 112 int32_t ref_dest = SH::read_stack(ri->sp + 2);
20941 112 int32_t cs = SH::read_stack(ri->sp + 1) / 10000;
20942 112 int32_t cs_dest = SH::read_stack(ri->sp + 0) / 10000;
20943
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
112 if (user_paldata* pd_dest = checkPalData(ref_dest))
20944 {
20945
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
112 if (unsigned(cs) > 15)
20946 {
20947 Z_scripterrlog("Invalid CSet (%d) passed to paldata->CopyCSet(). Valid CSets are 0-15. Aborting.\n", cs);
20948 return;
20949 }
20950
2/2
✓ Branch 0 taken 1792 times.
✓ Branch 1 taken 112 times.
1904 for (int32_t q = 0; q < 16; ++q)
20951 {
20952 1792 pd_dest->colors[CSET(cs_dest) + q] = pd->colors[CSET(cs) + q];
20953 1792 set_bit(pd_dest->colors_used, CSET(cs_dest) + q, bool(get_bit(pd->colors_used, CSET(cs) + q)));
20954 1792 }
20955 112 }
20956 112 }
20957 112 }
20958
20959 //Loads a cset to paldata from memory
20960 1497 void user_paldata::load_cset(int32_t cset, int32_t dataset)
20961 {
20962 1497 byte* si = colordata + CSET(dataset) * 3;
20963
2/2
✓ Branch 0 taken 23952 times.
✓ Branch 1 taken 1497 times.
25449 for (int32_t q = 0; q < 16; ++q)
20964 {
20965 23952 int32_t ind = CSET(cset) + q;
20966 23952 colors[ind].r = scripting_read_pal_color(si[0]);
20967 23952 colors[ind].g = scripting_read_pal_color(si[1]);
20968 23952 colors[ind].b = scripting_read_pal_color(si[2]);
20969 23952 set_bit(colors_used, ind, true);
20970 23952 si += 3;
20971 23952 }
20972 1497 }
20973
20974 //Loads a cset to paldata from the main palette
20975 1472 void user_paldata::load_cset_main(int32_t cset)
20976 {
20977
2/2
✓ Branch 0 taken 23552 times.
✓ Branch 1 taken 1472 times.
25024 for (int32_t q = 0; q < 16; ++q)
20978 {
20979 23552 int32_t ind = CSET(cset) + q;
20980 23552 colors[ind].r = scripting_read_pal_color(RAMpal[ind].r);
20981 23552 colors[ind].g = scripting_read_pal_color(RAMpal[ind].g);
20982 23552 colors[ind].b = scripting_read_pal_color(RAMpal[ind].b);
20983 23552 set_bit(colors_used, ind, true);
20984 23552 }
20985 1472 }
20986
20987 //Writes to a memory cset from paldata
20988 2905 void user_paldata::write_cset(int32_t cset, int32_t dataset)
20989 {
20990 2905 byte* si = colordata + CSET(dataset) * 3;
20991
2/2
✓ Branch 0 taken 46480 times.
✓ Branch 1 taken 2905 times.
49385 for (int32_t q = 0; q < 16; ++q)
20992 {
20993 46480 int32_t ind = CSET(cset) + q;
20994
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46480 times.
46480 if (get_bit(colors_used, ind))
20995 {
20996 46480 si[0] = scripting_write_pal_color(colors[ind].r);
20997 46480 si[1] = scripting_write_pal_color(colors[ind].g);
20998 46480 si[2] = scripting_write_pal_color(colors[ind].b);
20999 46480 }
21000 46480 si += 3;
21001 46480 }
21002 2905 }
21003
21004 //Writes to a main palette cset from paldata
21005 5791 void user_paldata::write_cset_main(int32_t cset)
21006 {
21007
2/2
✓ Branch 0 taken 92656 times.
✓ Branch 1 taken 5791 times.
98447 for (int32_t q = 0; q < 16; ++q)
21008 {
21009 92656 int32_t ind = CSET(cset) + q;
21010
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92656 times.
92656 if (get_bit(colors_used, ind))
21011 {
21012 92656 RAMpal[ind] = colors[ind];
21013
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92656 times.
92656 if (!scripting_use_8bit_colors)
21014 92656 convertRGB(RAMpal[ind]);
21015 92656 }
21016 92656 }
21017 5791 }
21018
21019
21020 //Checks a memory cset from
21021
21022
21023
21024
21025 3425 bool user_paldata::check_cset(int32_t cset, int32_t dataset)
21026 {
21027 3425 byte* si = colordata + CSET(dataset) * 3;
21028
2/2
✓ Branch 0 taken 11375 times.
✓ Branch 1 taken 520 times.
11895 for (int32_t q = 0; q < 16; ++q)
21029 {
21030 11375 int32_t ind = CSET(cset) + q;
21031
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11375 times.
11375 if (get_bit(colors_used, ind))
21032 {
21033
2/2
✓ Branch 0 taken 9482 times.
✓ Branch 1 taken 1893 times.
11375 if (scripting_read_pal_color(si[0]) != colors[ind].r)
21034 1893 return true;
21035
2/2
✓ Branch 0 taken 8470 times.
✓ Branch 1 taken 1012 times.
9482 if (scripting_read_pal_color(si[1]) != colors[ind].g)
21036 1012 return true;
21037
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8470 times.
8470 if (scripting_read_pal_color(si[2]) != colors[ind].b)
21038 return true;
21039 8470 }
21040 8470 si += 3;
21041 8470 }
21042 520 return false;
21043 3425 }
21044
21045 //Checks a memory cset from the main palette
21046 17154 bool user_paldata::check_cset_main(int32_t cset)
21047 {
21048
2/2
✓ Branch 0 taken 188844 times.
✓ Branch 1 taken 11363 times.
200207 for (int32_t q = 0; q < 16; ++q)
21049 {
21050 188844 int32_t ind = CSET(cset) + q;
21051
2/2
✓ Branch 0 taken 96064 times.
✓ Branch 1 taken 92780 times.
188844 if (get_bit(colors_used, ind))
21052 {
21053
2/2
✓ Branch 0 taken 88937 times.
✓ Branch 1 taken 3843 times.
92780 if (scripting_read_pal_color(RAMpal[ind].r) != colors[ind].r)
21054 3843 return true;
21055
2/2
✓ Branch 0 taken 87200 times.
✓ Branch 1 taken 1737 times.
88937 if (scripting_read_pal_color(RAMpal[ind].g) != colors[ind].g)
21056 1737 return true;
21057
2/2
✓ Branch 0 taken 211 times.
✓ Branch 1 taken 86989 times.
87200 if (scripting_read_pal_color(RAMpal[ind].b) != colors[ind].b)
21058 211 return true;
21059 86989 }
21060 183053 }
21061 11363 return false;
21062 17154 }
21063
21064 //Mixes a color between two paldatas
21065 139696 RGB user_paldata::mix_color(RGB start, RGB end, double percent, int32_t color_space)
21066 {
21067 139696 double upper = scripting_max_color_val;
21068 139696 int32_t direction = 0;
21069
1/13
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 139696 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
139696 switch (color_space)
21070 {
21071 case CSPACE_RGB:
21072 279392 return _RGB(byte(vbound(double(zc::math::Lerp(start.r, end.r, percent)), 0.0, upper)),
21073 139696 byte(vbound(double(zc::math::Lerp(start.g, end.g, percent)), 0.0, upper)),
21074 139696 byte(vbound(double(zc::math::Lerp(start.b, end.b, percent)), 0.0, upper)));
21075 case CSPACE_CMYK:
21076 {
21077 double convert_start[4];
21078 double convert_end[4];
21079 double convert_result[4];
21080 RGBTo(start, convert_start, color_space);
21081 RGBTo(end, convert_end, color_space);
21082 convert_result[0] = zc::math::Lerp(convert_start[0], convert_end[0], percent);
21083 convert_result[1] = zc::math::Lerp(convert_start[1], convert_end[1], percent);
21084 convert_result[2] = zc::math::Lerp(convert_start[2], convert_end[2], percent);
21085 convert_result[3] = zc::math::Lerp(convert_start[3], convert_end[3], percent);
21086 return RGBFrom(convert_result, color_space);
21087 }
21088 case CSPACE_HSV_CW:
21089 if (color_space == CSPACE_HSV_CW)
21090 direction = 1;
21091 [[fallthrough]];
21092 case CSPACE_HSV_CCW:
21093 if (color_space == CSPACE_HSV_CCW)
21094 direction = -1;
21095 [[fallthrough]];
21096 case CSPACE_HSV:
21097 {
21098 double convert_start[3];
21099 double convert_end[3];
21100 double convert_result[3];
21101 RGBTo(start, convert_start, color_space);
21102 RGBTo(end, convert_end, color_space);
21103 convert_result[0] = WrapLerp(convert_start[0], convert_end[0], percent, 0.0, 1.0, direction);
21104 convert_result[1] = zc::math::Lerp(convert_start[1], convert_end[1], percent);
21105 convert_result[2] = zc::math::Lerp(convert_start[2], convert_end[2], percent);
21106 return RGBFrom(convert_result, color_space);
21107 }
21108 case CSPACE_HSL_CW:
21109 if (color_space == CSPACE_HSL_CW)
21110 direction = 1;
21111 [[fallthrough]];
21112 case CSPACE_HSL_CCW:
21113 if (color_space == CSPACE_HSL_CCW)
21114 direction = -1;
21115 [[fallthrough]];
21116 case CSPACE_HSL:
21117 {
21118 double convert_start[3];
21119 double convert_end[3];
21120 double convert_result[3];
21121 RGBTo(start, convert_start, color_space);
21122 RGBTo(end, convert_end, color_space);
21123 convert_result[0] = WrapLerp(convert_start[0], convert_end[0], percent, 0.0, 1.0, direction);
21124 convert_result[1] = zc::math::Lerp(convert_start[1], convert_end[1], percent);
21125 convert_result[2] = zc::math::Lerp(convert_start[2], convert_end[2], percent);
21126 return RGBFrom(convert_result, color_space);
21127 }
21128 case CSPACE_LAB:
21129 {
21130 double convert_start[3];
21131 double convert_end[3];
21132 double convert_result[3];
21133 RGBTo(start, convert_start, color_space);
21134 RGBTo(end, convert_end, color_space);
21135 convert_result[0] = zc::math::Lerp(convert_start[0], convert_end[0], percent);
21136 convert_result[1] = zc::math::Lerp(convert_start[1], convert_end[1], percent);
21137 convert_result[2] = zc::math::Lerp(convert_start[2], convert_end[2], percent);
21138 return RGBFrom(convert_result, color_space);
21139 }
21140 case CSPACE_LCH_CW:
21141 if (color_space == CSPACE_LCH_CW)
21142 direction = 1;
21143 [[fallthrough]];
21144 case CSPACE_LCH_CCW:
21145 if (color_space == CSPACE_LCH_CCW)
21146 direction = -1;
21147 [[fallthrough]];
21148 case CSPACE_LCH:
21149 {
21150 double convert_start[3];
21151 double convert_end[3];
21152 double convert_result[3];
21153 RGBTo(start, convert_start, color_space);
21154 RGBTo(end, convert_end, color_space);
21155 convert_result[0] = zc::math::Lerp(convert_start[0], convert_end[0], percent);
21156 convert_result[1] = zc::math::Lerp(convert_start[1], convert_end[1], percent);
21157 convert_result[2] = WrapLerp(convert_start[2], convert_end[2], percent, 0.0, 360.0, direction);
21158 return RGBFrom(convert_result, color_space);
21159 }
21160 }
21161 return start;
21162 139696 }
21163
21164 void user_paldata::RGBTo(RGB c, double arr[], int32_t color_space)
21165 {
21166 //From easyrgb.com/en/math.php
21167 double upper = scripting_max_color_val;
21168 double r = vbound(c.r / upper, 0.0, 1.0);
21169 double g = vbound(c.g / upper, 0.0, 1.0);
21170 double b = vbound(c.b / upper, 0.0, 1.0);
21171 switch (color_space)
21172 {
21173 case CSPACE_CMYK:
21174 {
21175 double c = 1.0 - r;
21176 double m = 1.0 - g;
21177 double y = 1.0 - b;
21178
21179 double k = 1.0;
21180
21181 if (c < k) k = c;
21182 if (m < k) k = m;
21183 if (y < k) k = y;
21184 if (k == 1)
21185 {
21186 c = 0.0;
21187 m = 0.0;
21188 y = 0.0;
21189 }
21190 else
21191 {
21192 c = (c - k) / (1.0 - k);
21193 m = (m - k) / (1.0 - k);
21194 y = (y - k) / (1.0 - k);
21195 }
21196 arr[0] = c;
21197 arr[1] = m;
21198 arr[2] = y;
21199 arr[3] = k;
21200 break;
21201 }
21202 case CSPACE_HSV_CW:
21203 case CSPACE_HSV_CCW:
21204 case CSPACE_HSV:
21205 {
21206 double min_val = std::min(std::min(r, g), b);
21207 double max_val = std::max(std::max(r, g), b);
21208 double del_max = max_val - min_val;
21209
21210 double h = 0;
21211 double s = 0;
21212 double v = max_val;
21213
21214 if (del_max != 0) //Set chroma if not gray
21215 {
21216 s = del_max / max_val;
21217
21218 double del_r = (((max_val - r) / 6.0) + (del_max / 2.0)) / del_max;
21219 double del_g = (((max_val - g) / 6.0) + (del_max / 2.0)) / del_max;
21220 double del_b = (((max_val - b) / 6.0) + (del_max / 2.0)) / del_max;
21221
21222 if (r == max_val) h = del_b - del_g;
21223 else if (g == max_val) h = (1.0 / 3.0) + del_r - del_b;
21224 else if (b == max_val) h = (2.0 / 3.0) + del_g - del_r;
21225
21226 if (h < 0) ++h;
21227 if (h > 1) --h;
21228 }
21229
21230 arr[0] = h;
21231 arr[1] = s;
21232 arr[2] = v;
21233 break;
21234 }
21235 case CSPACE_HSL_CW:
21236 case CSPACE_HSL_CCW:
21237 case CSPACE_HSL:
21238 {
21239 double min_val = std::min(std::min(r, g), b);
21240 double max_val = std::max(std::max(r, g), b);
21241 double del_max = max_val - min_val;
21242
21243 double h = 0;
21244 double s = 0;
21245 double l = (max_val + min_val) / 2.0;
21246
21247 if (del_max != 0) //Set chroma if not gray
21248 {
21249 if (l < 0.5) s = del_max / (max_val + min_val);
21250 else s = del_max / (2 - max_val - min_val);
21251
21252 double del_r = (((max_val - r) / 6.0) + (del_max / 2.0)) / del_max;
21253 double del_g = (((max_val - g) / 6.0) + (del_max / 2.0)) / del_max;
21254 double del_b = (((max_val - b) / 6.0) + (del_max / 2.0)) / del_max;
21255
21256 if (r == max_val) h = del_b - del_g;
21257 else if (g == max_val) h = (1.0 / 3.0) + del_r - del_b;
21258 else if (b == max_val) h = (2.0 / 3.0) + del_g - del_r;
21259
21260 if (h < 0) ++h;
21261 if (h > 1) --h;
21262 }
21263
21264 arr[0] = h;
21265 arr[1] = s;
21266 arr[2] = l;
21267 break;
21268 }
21269 case CSPACE_LAB:
21270 {
21271 if (r > 0.04045) r = pow(((r + 0.055) / 1.055), 2.4);
21272 else r /= 12.92;
21273 if (g > 0.04045) g = pow(((g + 0.055) / 1.055), 2.4);
21274 else g /= 12.92;
21275 if (b > 0.04045) b = pow(((b + 0.055) / 1.055), 2.4);
21276 else b /= 12.92;
21277
21278 double x = r * 0.4124 + g * 0.3576 + b * 0.1805;
21279 double y = r * 0.2126 + g * 0.7152 + b * 0.0722;
21280 double z = r * 0.0193 + g * 0.1192 + b * 0.9505;
21281
21282 if (x > 0.008856) x = pow(x, 1.0 / 3.0);
21283 else x = (7.787 * x) + (16.0 / 116.0);
21284 if (y > 0.008856) y = pow(y, 1.0 / 3.0);
21285 else y = (7.787 * y) + (16.0 / 116.0);
21286 if (z > 0.008856) z = pow(z, 1.0 / 3.0);
21287 else z = (7.787 * z) + (16.0 / 116.0);
21288
21289 double CIEL = (116 * y) - 16;
21290 double CIEa = 500 * (x - y);
21291 double CIEb = 200 * (y - z);
21292
21293 arr[0] = CIEL;
21294 arr[1] = CIEa;
21295 arr[2] = CIEb;
21296 break;
21297 }
21298 case CSPACE_LCH_CW:
21299 case CSPACE_LCH_CCW:
21300 case CSPACE_LCH:
21301 {
21302 if (r > 0.04045) r = pow(((r + 0.055) / 1.055), 2.4);
21303 else r /= 12.92;
21304 if (g > 0.04045) g = pow(((g + 0.055) / 1.055), 2.4);
21305 else g /= 12.92;
21306 if (b > 0.04045) b = pow(((b + 0.055) / 1.055), 2.4);
21307 else b /= 12.92;
21308
21309 double x = r * 0.4124 + g * 0.3576 + b * 0.1805;
21310 double y = r * 0.2126 + g * 0.7152 + b * 0.0722;
21311 double z = r * 0.0193 + g * 0.1192 + b * 0.9505;
21312
21313 if (x > 0.008856) x = pow(x, 1.0 / 3.0);
21314 else x = (7.787 * x) + (16.0 / 116.0);
21315 if (y > 0.008856) y = pow(y, 1.0 / 3.0);
21316 else y = (7.787 * y) + (16.0 / 116.0);
21317 if (z > 0.008856) z = pow(z, 1.0 / 3.0);
21318 else z = (7.787 * z) + (16.0 / 116.0);
21319
21320 double CIEL = (116 * y) - 16;
21321 double CIEa = 500 * (x - y);
21322 double CIEb = 200 * (y - z);
21323
21324 double h = atan2(CIEb, CIEa);
21325 if (h > 0) h = (h / PI) * 180;
21326 else h = 360 - (abs(h) / PI) * 180;
21327
21328 double CIEC = sqrt(pow(CIEa, 2) + pow(CIEb, 2));
21329
21330 arr[0] = CIEL;
21331 arr[1] = CIEC;
21332 arr[2] = h;
21333 break;
21334 }
21335 }
21336
21337 }
21338
21339 RGB user_paldata::RGBFrom(double arr[], int32_t color_space)
21340 {
21341 double upper = scripting_max_color_val;
21342 double r = 0.0;
21343 double g = 0.0;
21344 double b = 0.0;
21345 switch (color_space)
21346 {
21347 case CSPACE_CMYK:
21348 {
21349 double c = (arr[0] * (1 - arr[3]) + arr[3]);
21350 double m = (arr[1] * (1 - arr[3]) + arr[3]);
21351 double y = (arr[2] * (1 - arr[3]) + arr[3]);
21352
21353 r = vbound((1 - c) * upper, 0.0, upper);
21354 g = vbound((1 - m) * upper, 0.0, upper);
21355 b = vbound((1 - y) * upper, 0.0, upper);
21356 return _RGB(r, g, b);
21357 break;
21358 }
21359 case CSPACE_HSV_CW:
21360 case CSPACE_HSV_CCW:
21361 case CSPACE_HSV:
21362 {
21363 double h = arr[0];
21364 double s = arr[1];
21365 double v = arr[2];
21366
21367 if (s == 0)
21368 {
21369 r = v;
21370 g = v;
21371 b = v;
21372 }
21373 else
21374 {
21375 double var_h = h * 6;
21376 if (var_h >= 6) var_h = 0;
21377 int32_t var_i = floor(var_h);
21378 double var_1 = v * (1 - s);
21379 double var_2 = v * (1 - s * (var_h - var_i));
21380 double var_3 = v * (1 - s * (1 - (var_h - var_i)));
21381
21382 switch (var_i)
21383 {
21384 case 0:
21385 r = v;
21386 g = var_3;
21387 b = var_1;
21388 break;
21389 case 1:
21390 r = var_2;
21391 g = v;
21392 b = var_1;
21393 break;
21394 case 2:
21395 r = var_1;
21396 g = v;
21397 b = var_3;
21398 break;
21399 case 3:
21400 r = var_1;
21401 g = var_2;
21402 b = v;
21403 break;
21404 case 4:
21405 r = var_3;
21406 g = var_1;
21407 b = v;
21408 break;
21409 default:
21410 r = v;
21411 g = var_1;
21412 b = var_2;
21413 }
21414 }
21415
21416 r = vbound(r * upper, 0.0, upper);
21417 g = vbound(g * upper, 0.0, upper);
21418 b = vbound(b * upper, 0.0, upper);
21419
21420 return _RGB(r, g, b);
21421 }
21422 case CSPACE_HSL_CW:
21423 case CSPACE_HSL_CCW:
21424 case CSPACE_HSL:
21425 {
21426 double h = arr[0];
21427 double s = arr[1];
21428 double l = arr[2];
21429
21430 if (s == 0)
21431 {
21432 r = l;
21433 g = l;
21434 b = l;
21435 }
21436 else
21437 {
21438 double var_1;
21439 double var_2;
21440 if (l < 0.5)var_2 = l * (1 + s);
21441 else var_2 = (l + s) - (s * l);
21442
21443 var_1 = 2 * l - var_2;
21444
21445 r = HueToRGB(var_1, var_2, h + (1.0 / 3.0));
21446 g = HueToRGB(var_1, var_2, h);
21447 b = HueToRGB(var_1, var_2, h - (1.0 / 3.0));
21448 }
21449
21450 r = vbound(r * upper, 0.0, upper);
21451 g = vbound(g * upper, 0.0, upper);
21452 b = vbound(b * upper, 0.0, upper);
21453
21454 return _RGB(r, g, b);
21455 }
21456 case CSPACE_LAB:
21457 {
21458 double CIEL = arr[0];
21459 double CIEa = arr[1];
21460 double CIEb = arr[2];
21461
21462 double var_y = (CIEL + 16) / 116.0;
21463 double var_x = CIEa / 500.0 + var_y;
21464 double var_z = var_y - CIEb / 200.0;
21465
21466 if (pow(var_x, 3) > 0.008856) var_x = pow(var_x, 3);
21467 else var_x = (var_x - 16.0 / 116.0) / 7.787;
21468 if (pow(var_y, 3) > 0.008856) var_y = pow(var_y, 3);
21469 else var_y = (var_y - 16.0 / 116.0) / 7.787;
21470 if (pow(var_z, 3) > 0.008856) var_z = pow(var_z, 3);
21471 else var_z = (var_z - 16.0 / 116.0) / 7.787;
21472
21473 r = var_x * 3.2406 + var_y * -1.5372 + var_z * -0.4986;
21474 g = var_x * -0.9689 + var_y * 1.8758 + var_z * 0.0415;
21475 b = var_x * 0.0557 + var_y * -0.2040 + var_z * 1.0570;
21476
21477 if (r > 0.0031308) r = 1.055 * pow(r, (1 / 2.4)) - 0.055;
21478 else r = 12.92 * r;
21479 if (g > 0.0031308) g = 1.055 * pow(g, (1 / 2.4)) - 0.055;
21480 else g = 12.92 * g;
21481 if (b > 0.0031308) b = 1.055 * pow(b, (1 / 2.4)) - 0.055;
21482 else b = 12.92 * b;
21483
21484 r = vbound(r * upper, 0.0, upper);
21485 g = vbound(g * upper, 0.0, upper);
21486 b = vbound(b * upper, 0.0, upper);
21487
21488 return _RGB(r, g, b);
21489 }
21490 case CSPACE_LCH_CW:
21491 case CSPACE_LCH_CCW:
21492 case CSPACE_LCH:
21493 {
21494 double CIEL = arr[0];
21495 double CIEa = cos((arr[2] * PI) / 180.0) * arr[1];
21496 double CIEb = sin((arr[2] * PI) / 180.0) * arr[1];
21497
21498 double var_y = (CIEL + 16) / 116.0;
21499 double var_x = CIEa / 500.0 + var_y;
21500 double var_z = var_y - CIEb / 200.0;
21501
21502 if (pow(var_y, 3) > 0.008856) var_y = pow(var_y, 3);
21503 else var_y = (var_y - 16.0 / 116.0) / 7.787;
21504 if (pow(var_x, 3) > 0.008856) var_x = pow(var_x, 3);
21505 else var_x = (var_x - 16.0 / 116.0) / 7.787;
21506 if (pow(var_z, 3) > 0.008856) var_z = pow(var_z, 3);
21507 else var_z = (var_z - 16.0 / 116.0) / 7.787;
21508
21509 r = var_x * 3.2406 + var_y * -1.5372 + var_z * -0.4986;
21510 g = var_x * -0.9689 + var_y * 1.8758 + var_z * 0.0415;
21511 b = var_x * 0.0557 + var_y * -0.2040 + var_z * 1.0570;
21512
21513 if (r > 0.0031308) r = 1.055 * pow(r, (1 / 2.4)) - 0.055;
21514 else r = 12.92 * r;
21515 if (g > 0.0031308) g = 1.055 * pow(g, (1 / 2.4)) - 0.055;
21516 else g = 12.92 * g;
21517 if (b > 0.0031308) b = 1.055 * pow(b, (1 / 2.4)) - 0.055;
21518 else b = 12.92 * b;
21519
21520 r = vbound(r * upper, 0.0, upper);
21521 g = vbound(g * upper, 0.0, upper);
21522 b = vbound(b * upper, 0.0, upper);
21523
21524 return _RGB(r, g, b);
21525 }
21526 }
21527 return _RGB(0, 0, 0);
21528 }
21529 double user_paldata::HueToRGB(double v1, double v2, double vH)
21530 {
21531 if (vH < 0) vH += 1;
21532 if (vH > 1) vH -= 1;
21533 if ((6 * vH) < 1) return (v1 + (v2 - v1) * 6 * vH);
21534 if ((2 * vH) < 1) return (v2);
21535 if ((3 * vH) < 2) return (v1 + (v2 - v1) * ((2.0 / 3.0) - vH) * 6);
21536 return (v1);
21537 }
21538
21539 double user_paldata::WrapLerp(double a, double b, double t, double min, double max, int32_t direction)
21540 {
21541 double dif = abs(a - b);
21542 double range = abs(max - min);
21543
21544 switch (direction)
21545 {
21546 case 0:
21547 if (dif > range * 0.5)
21548 dif = range - dif;
21549 if (a + dif == b)
21550 direction = 1;
21551 else
21552 direction = -1;
21553 break;
21554 case 1:
21555 if (b < a)
21556 dif = range - dif;
21557 break;
21558 case -1:
21559 if (b > a)
21560 dif = range - dif;
21561 break;
21562 }
21563
21564 double ret = zc::math::Lerp(a, a + dif * direction, t);
21565
21566 if (ret <= min)
21567 ret += range;
21568 else if (ret >= max)
21569 ret -= range;
21570 return ret;
21571 }
21572
21573 //Mixes an entire palette given two paldatas
21574 5231 void user_paldata::mix(user_paldata *pal_start, user_paldata *pal_end, double percent, int32_t color_space, int32_t start_color, int32_t end_color)
21575 {
21576
2/2
✓ Branch 0 taken 184496 times.
✓ Branch 1 taken 5231 times.
189727 for (int32_t q = start_color; q < end_color; ++q)
21577 {
21578
3/4
✓ Branch 0 taken 139696 times.
✓ Branch 1 taken 44800 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 139696 times.
184496 if (get_bit(pal_start->colors_used, q) && get_bit(pal_end->colors_used, q)) {
21579 139696 RGB start = pal_start->colors[q];
21580 139696 RGB end = pal_end->colors[q];
21581 139696 colors[q] = mix_color(start, end, percent, color_space);
21582 139696 set_bit(colors_used, q, true);
21583 139696 }
21584 184496 }
21585 5231 }
21586
21587 53 void item_display_name(const bool setter)
21588 {
21589 53 int32_t ID = ri->idata;
21590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
53 if(unsigned(ID) >= MAXITEMS)
21591 return;
21592 53 int32_t arrayptr = get_register(sarg1);
21593
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
53 if(setter)
21594 {
21595 std::string str;
21596 ArrayH::getString(arrayptr, str, 255);
21597 strcpy(itemsbuf[ID].display_name, str.c_str());
21598 }
21599 else
21600 {
21601
3/6
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 53 times.
✓ Branch 4 taken 53 times.
✗ Branch 5 not taken.
53 if(ArrayH::setArray(arrayptr, string(itemsbuf[ID].display_name)) == SH::_Overflow)
21602 Z_scripterrlog("Array supplied to 'itemdata->GetDisplayName()' not large enough\n");
21603 }
21604 53 }
21605 void item_shown_name()
21606 {
21607 int32_t ID = ri->idata;
21608 if(unsigned(ID) >= MAXITEMS)
21609 return;
21610 int32_t arrayptr = get_register(sarg1);
21611 if(ArrayH::setArray(arrayptr, itemsbuf[ID].get_name()) == SH::_Overflow)
21612 Z_scripterrlog("Array supplied to 'itemdata->GetShownName()' not large enough\n");
21613 }
21614
21615 void FFScript::do_getDMapData_dmapname(const bool v)
21616 {
21617 int32_t ID = ri->dmapsref;
21618 int32_t arrayptr = get_register(sarg1);
21619
21620 if(BC::checkDMapID(ID) != SH::_NoError)
21621 return;
21622
21623 if(ArrayH::setArray(arrayptr, string(DMaps[ID].name)) == SH::_Overflow)
21624 Z_scripterrlog("Array supplied to 'dmapdata->GetName()' not large enough\n");
21625 }
21626
21627 void FFScript::do_setDMapData_dmapname(const bool v)
21628 {
21629 int32_t ID = ri->dmapsref;
21630 int32_t arrayptr = get_register(sarg1);
21631
21632 string filename_str;
21633
21634 if(BC::checkDMapID(ID) != SH::_NoError)
21635 return;
21636
21637
21638 ArrayH::getString(arrayptr, filename_str, 22);
21639 strncpy(DMaps[ID].name, filename_str.c_str(), 21);
21640 DMaps[ID].name[20]='\0';
21641 }
21642
21643 void FFScript::do_getDMapData_dmaptitle(const bool v)
21644 {
21645 int32_t ID = ri->dmapsref;
21646 int32_t arrayptr = get_register(sarg1);
21647
21648 if(BC::checkDMapID(ID) != SH::_NoError)
21649 return;
21650
21651 if (!get_qr(qr_OLD_DMAP_INTRO_STRINGS))
21652 {
21653 ArrayManager am(arrayptr);
21654 am.resize(DMaps[ID].title.size() + 1);
21655 }
21656 if(ArrayH::setArray(arrayptr, string(DMaps[ID].title)) == SH::_Overflow)
21657 Z_scripterrlog("Array supplied to 'dmapdata->GetTitle()' not large enough\n");
21658 }
21659
21660 void FFScript::do_setDMapData_dmaptitle(const bool v)
21661 {
21662 int32_t ID = ri->dmapsref;
21663 int32_t arrayptr = get_register(sarg1);
21664 string filename_str;
21665
21666 if(BC::checkDMapID(ID) != SH::_NoError)
21667 return;
21668
21669 if (get_qr(qr_OLD_DMAP_INTRO_STRINGS))
21670 {
21671 char namestr[21];
21672 ArrayH::getString(arrayptr, filename_str, 21);
21673 strncpy(namestr, filename_str.c_str(), 20);
21674 namestr[20] = '\0';
21675 DMaps[ID].title.assign(namestr);
21676 }
21677 else
21678 {
21679 ArrayH::getString(arrayptr, filename_str, ArrayH::getSize(arrayptr));
21680 DMaps[ID].title = filename_str;
21681 }
21682 }
21683
21684 void FFScript::do_getDMapData_dmapintro(const bool v)
21685 {
21686 int32_t ID = ri->dmapsref;
21687 int32_t arrayptr = get_register(sarg1);
21688
21689 if(BC::checkDMapID(ID) != SH::_NoError)
21690 return;
21691
21692 if(ArrayH::setArray(arrayptr, string(DMaps[ID].intro)) == SH::_Overflow)
21693 Z_scripterrlog("Array supplied to 'dmapdata->GetIntro()' not large enough\n");
21694 }
21695
21696 void FFScript::do_setDMapData_dmapintro(const bool v)
21697 {
21698 int32_t ID = ri->dmapsref;
21699 int32_t arrayptr = get_register(sarg1);
21700 string filename_str;
21701
21702 if(BC::checkDMapID(ID) != SH::_NoError)
21703 return;
21704
21705
21706 ArrayH::getString(arrayptr, filename_str, 73);
21707 strncpy(DMaps[ID].intro, filename_str.c_str(), 72);
21708 DMaps[ID].intro[72]='\0';
21709 }
21710
21711 void FFScript::do_getDMapData_music(const bool v)
21712 {
21713 int32_t ID = ri->dmapsref;
21714 int32_t arrayptr = get_register(sarg1);
21715
21716 if(BC::checkDMapID(ID) != SH::_NoError)
21717 return;
21718
21719 if(ArrayH::setArray(arrayptr, string(DMaps[ID].tmusic)) == SH::_Overflow)
21720 Z_scripterrlog("Array supplied to 'dmapdata->GetMusic()' not large enough\n");
21721 }
21722
21723 void FFScript::do_setDMapData_music(const bool v)
21724 {
21725 int32_t ID = ri->dmapsref;
21726 int32_t arrayptr = get_register(sarg1);
21727 string filename_str;
21728
21729 if(BC::checkDMapID(ID) != SH::_NoError)
21730 return;
21731
21732
21733 ArrayH::getString(arrayptr, filename_str, 56);
21734 strncpy(DMaps[ID].tmusic, filename_str.c_str(), 55);
21735 DMaps[ID].tmusic[55]='\0';
21736 }
21737
21738 6365 void FFScript::do_loadnpcdata(const bool v)
21739 {
21740 6365 int32_t ID = SH::get_arg(sarg1, v) / 10000;
21741
21742
2/4
✓ Branch 0 taken 6365 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6365 times.
6365 if ( ID < 1 || ID > (MAXGUYS-1) )
21743 {
21744 Z_scripterrlog("Invalid NPC ID passed to Game->LoadNPCData: %d\n", ID);
21745 ri->npcdataref = MAX_DWORD;
21746 }
21747
21748 6365 else ri->npcdataref = ID;
21749 6365 }
21750 24 void FFScript::do_loadmessagedata(const bool v)
21751 {
21752 24 int32_t ID = SH::get_arg(sarg1, v) / 10000;
21753
21754
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
24 if ( ID < 1 || ID > (msg_count-1) )
21755 {
21756 Z_scripterrlog("Invalid Message ID passed to Game->LoadMessageData: %d\n", ID);
21757 ri->zmsgref = MAX_DWORD;
21758 }
21759
21760 24 else ri->zmsgref = ID;
21761 24 }
21762 //same syntax as loadmessage data
21763 //the input is an array
21764 24 void FFScript::do_messagedata_setstring(const bool v)
21765 {
21766 24 int32_t arrayptr = get_register(sarg1);
21767 24 int32_t ID = ri->zmsgref;
21768
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if(BC::checkMessage(ID) != SH::_NoError)
21769 return;
21770
21771 24 std::string s;
21772
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ArrayH::getString(arrayptr, s, MSG_NEW_SIZE);
21773
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 MsgStrings[ID].setFromLegacyEncoding(s);
21774 24 }
21775 void FFScript::do_messagedata_getstring(const bool v)
21776 {
21777 int32_t ID = ri->zmsgref;
21778 int32_t arrayptr = get_register(sarg1);
21779
21780 if(BC::checkMessage(ID) != SH::_NoError)
21781 return;
21782
21783 if(ArrayH::setArray(arrayptr, MsgStrings[ID].s) == SH::_Overflow)
21784 Z_scripterrlog("Array supplied to 'messagedata->Get()' not large enough\n");
21785 }
21786
21787 432438 void FFScript::do_loadcombodata(const bool v)
21788 {
21789 432438 int32_t ID = SH::get_arg(sarg1, v) / 10000;
21790
21791
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 432438 times.
432438 if ( (unsigned)ID > (MAXCOMBOS-1) )
21792 {
21793 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
21794 ri->combosref = 0;
21795 }
21796
21797 432438 else ri->combosref = ID;
21798 432438 }
21799
21800 3209679 void FFScript::do_loadmapdata_tempscr(const bool v)
21801 {
21802 3209679 int32_t layer = SH::get_arg(sarg1, v) / 10000;
21803
21804
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3209679 times.
3209679 if (BC::checkBounds(layer, 0, 6) != SH::_NoError)
21805 {
21806 ri->mapsref = 0;
21807 set_register(sarg1, ri->mapsref);
21808 return;
21809 }
21810
21811 3209679 ri->mapsref = create_mapdata_temp_ref(mapdata_type::TemporaryCurrentRegion, cur_screen, layer);
21812 3209679 set_register(sarg1, ri->mapsref);
21813 3209679 }
21814
21815 void FFScript::do_loadmapdata_tempscr2(const bool v)
21816 {
21817 int32_t layer = SH::get_arg(sarg1, v) / 10000;
21818 int32_t screen = SH::get_arg(sarg2, v) / 10000;
21819
21820 if (BC::checkBounds(layer, 0, 6) != SH::_NoError)
21821 {
21822 ri->mapsref = 0;
21823 set_register(sarg1, ri->mapsref);
21824 return;
21825 }
21826
21827 if (!is_in_current_region(screen))
21828 {
21829 scripting_log_error_with_context("Must use a screen in the current region. got: {}", screen);
21830 ri->mapsref = 0;
21831 set_register(sarg1, ri->mapsref);
21832 return;
21833 }
21834
21835 ri->mapsref = create_mapdata_temp_ref(mapdata_type::TemporaryCurrentScreen, screen, layer);
21836 set_register(sarg1, ri->mapsref);
21837 }
21838
21839 static void do_loadtmpscrforcombopos(const bool v)
21840 {
21841 int32_t layer = SH::get_arg(sarg1, v) / 10000;
21842 rpos_t rpos = (rpos_t)(SH::get_arg(sarg2, v) / 10000);
21843
21844 if (BC::checkBoundsRpos(rpos, (rpos_t)0, region_max_rpos) != SH::_NoError)
21845 {
21846 ri->mapsref = 0;
21847 set_register(sarg1, ri->mapsref);
21848 return;
21849 }
21850 if (BC::checkBounds(layer, 0, 6) != SH::_NoError)
21851 {
21852 ri->mapsref = 0;
21853 set_register(sarg1, ri->mapsref);
21854 return;
21855 }
21856
21857 set_register(sarg1, create_mapdata_temp_ref(mapdata_type::TemporaryCurrentScreen, get_screen_for_rpos(rpos), layer));
21858 }
21859
21860 177544 void FFScript::do_loadmapdata_scrollscr(const bool v)
21861 {
21862 177544 int32_t layer = SH::get_arg(sarg1, v) / 10000;
21863
21864
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 177544 times.
177544 if (BC::checkBounds(layer, 0, 6) != SH::_NoError)
21865 {
21866 ri->mapsref = 0;
21867 set_register(sarg1, ri->mapsref);
21868 return;
21869 }
21870
21871 177544 ri->mapsref = create_mapdata_temp_ref(mapdata_type::TemporaryScrollingRegion, scrolling_hero_screen, layer);
21872 177544 set_register(sarg1, ri->mapsref);
21873 177544 }
21874
21875 void FFScript::do_loadmapdata_scrollscr2(const bool v)
21876 {
21877 int32_t layer = SH::get_arg(sarg1, v) / 10000;
21878 int32_t screen = SH::get_arg(sarg2, v) / 10000;
21879
21880 if (BC::checkBounds(layer, 0, 6) != SH::_NoError)
21881 {
21882 ri->mapsref = 0;
21883 set_register(sarg1, ri->mapsref);
21884 return;
21885 }
21886
21887 if (!is_in_scrolling_region(screen))
21888 {
21889 scripting_log_error_with_context("Must use a screen in the current scrolling region. got: {}", screen);
21890 ri->mapsref = 0;
21891 set_register(sarg1, ri->mapsref);
21892 return;
21893 }
21894
21895 ri->mapsref = create_mapdata_temp_ref(mapdata_type::TemporaryScrollingScreen, screen, layer);
21896 set_register(sarg1, ri->mapsref);
21897 }
21898
21899 void FFScript::do_loadshopdata(const bool v)
21900 {
21901 int32_t ID = SH::get_arg(sarg1, v) / 10000;
21902
21903 if ( (unsigned)ID > 255 )
21904 {
21905 Z_scripterrlog("Invalid Shop ID passed to Game->LoadShopData: %d\n", ID);
21906 ri->shopsref = 0;
21907 }
21908 else ri->shopsref = ID;
21909 }
21910
21911
21912 void FFScript::do_loadinfoshopdata(const bool v)
21913 {
21914 int32_t ID = SH::get_arg(sarg1, v) / 10000;
21915
21916 if ( (unsigned)ID > 255 )
21917 {
21918 Z_scripterrlog("Invalid Shop ID passed to Game->LoadShopData: %d\n", ID);
21919 ri->shopsref = 0;
21920 }
21921 else ri->shopsref = ID+NUMSHOPS;
21922 }
21923
21924 16 void FFScript::do_loadspritedata(const bool v)
21925 {
21926 16 int32_t ID = SH::get_arg(sarg1, v) / 10000;
21927
21928
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if ( (unsigned)ID > (MAXWPNS-1) )
21929 {
21930 Z_scripterrlog("Invalid Sprite ID passed to Game->LoadSpriteData: %d\n", ID);
21931 ri->spritedataref = 0;
21932 }
21933
21934 16 else ri->spritedataref = ID;
21935 16 }
21936
21937 10 void FFScript::do_loadbitmapid(const bool v)
21938 {
21939 10 int32_t ID = SH::get_arg(sarg1, v) / 10000;
21940
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 switch(ID)
21941 {
21942 case rtSCREEN:
21943 case rtBMP0:
21944 case rtBMP1:
21945 case rtBMP2:
21946 case rtBMP3:
21947 case rtBMP4:
21948 case rtBMP5:
21949 case rtBMP6:
21950 10 ri->bitmapref = ID+10; break;
21951 default:
21952 {
21953 Z_scripterrlog("Invalid Bitmap ID passed to Game->Load BitmapID: %d\n", ID);
21954 ri->bitmapref = 0; break;
21955 }
21956 }
21957 10 }
21958
21959 87669 void do_createlweapon(const bool v)
21960 {
21961 87669 const int32_t ID = SH::get_arg(sarg1, v) / 10000;
21962
21963
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 87669 times.
87669 if(BC::checkWeaponID(ID) != SH::_NoError)
21964 return;
21965
21966
1/2
✓ Branch 0 taken 87669 times.
✗ Branch 1 not taken.
87669 if ( Lwpns.has_space() )
21967 {
21968 87669 (void)Lwpns.add
21969 (
21970
1/2
✓ Branch 0 taken 87669 times.
✗ Branch 1 not taken.
175338 new weapon
21971 (
21972
1/2
✓ Branch 0 taken 87669 times.
✗ Branch 1 not taken.
87669 (zfix)0, /*X*/
21973
1/2
✓ Branch 0 taken 87669 times.
✗ Branch 1 not taken.
87669 (zfix)0, /*Y*/
21974
1/2
✓ Branch 0 taken 87669 times.
✗ Branch 1 not taken.
87669 (zfix)0, /*Z*/
21975 87669 ID, /*id*/
21976 0, /*type*/
21977 0, /*power*/
21978 0, /*dir*/
21979 -1, /*Parentid*/
21980
1/2
✓ Branch 0 taken 87669 times.
✗ Branch 1 not taken.
87669 Hero.getUID(), /*prntid*/
21981 false, /*isdummy*/
21982 1, /*script_gen*/
21983 1, /*islwpn*/
21984 87669 (ID==wWind?1:0) /*special*/
21985 )
21986 );
21987 87669 ri->lwpn = Lwpns.spr(Lwpns.Count() - 1)->getUID();
21988 87669 weapon *w = (weapon*)Lwpns.spr(Lwpns.Count()-1); //last created
21989 87669 w->screen_spawned = ri->screenref;
21990 87669 w->ScriptGenerated = 1;
21991 87669 w->isLWeapon = 1;
21992
1/2
✓ Branch 0 taken 87669 times.
✗ Branch 1 not taken.
87669 if(ID == wWind) w->specialinfo = 1;
21993 87669 Z_eventlog("Script created lweapon %ld with UID = %ld\n", ID, ri->lwpn);
21994 87669 }
21995 else
21996 {
21997 ri->lwpn = 0; // Now NULL
21998 Z_scripterrlog("Couldn't create lweapon %ld, screen lweapon limit reached\n", ID);
21999 }
22000 87669 }
22001
22002 209493 void do_createeweapon(const bool v)
22003 {
22004 209493 const int32_t ID = SH::get_arg(sarg1, v) / 10000;
22005
22006
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 209493 times.
209493 if(BC::checkWeaponID(ID) != SH::_NoError)
22007 return;
22008
22009
1/2
✓ Branch 0 taken 209493 times.
✗ Branch 1 not taken.
209493 if ( Ewpns.has_space() )
22010 {
22011 209493 addEwpn(0, 0, 0, ID, 0, 0, 0, -1,1); //Param 9 marks it as script-generated.
22012
4/6
✓ Branch 0 taken 150748 times.
✓ Branch 1 taken 58745 times.
✓ Branch 2 taken 150748 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 150748 times.
✗ Branch 5 not taken.
209493 if( ID > wEnemyWeapons || ( ID >= wScript1 && ID <= wScript10) )
22013 {
22014 209493 weapon *w = (weapon*)Ewpns.spr(Ewpns.Count()-1); //last created
22015 209493 w->screen_spawned = ri->screenref;
22016 209493 w->ScriptGenerated = 1;
22017 209493 w->isLWeapon = 0;
22018 209493 ri->ewpn = Ewpns.spr(Ewpns.Count() - 1)->getUID();
22019 209493 Z_eventlog("Script created eweapon %ld with UID = %ld\n", ID, ri->ewpn);
22020 209493 }
22021 else
22022 {
22023 Z_scripterrlog("Couldn't create eweapon %ld: Invalid ID/Type (%d) specified.\n", ID);
22024 return;
22025 }
22026 209493 }
22027 else
22028 {
22029 ri->ewpn = 0;
22030 Z_scripterrlog("Couldn't create eweapon %ld, screen eweapon limit reached\n", ID);
22031 }
22032 209493 }
22033
22034 22444 void do_createitem(const bool v)
22035 {
22036 22444 const int32_t ID = SH::get_arg(sarg1, v) / 10000;
22037
22038
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22444 times.
22444 if(BC::checkItemID(ID) != SH::_NoError)
22039 return;
22040
22041
1/2
✓ Branch 0 taken 22444 times.
✗ Branch 1 not taken.
22444 if ( items.has_space() )
22042 {
22043 22444 additem(0, (get_qr(qr_NOITEMOFFSET) ? 1: 0), ID, ipBIGRANGE);
22044 22444 sprite* item = items.spr(items.Count() - 1);
22045 22444 item->screen_spawned = ri->screenref;
22046 22444 ri->itemref = item->getUID();
22047 22444 Z_eventlog("Script created item \"%s\" with UID = %ld\n", item_string[ID], ri->itemref);
22048 22444 }
22049 else
22050 {
22051 ri->itemref = 0;
22052 Z_scripterrlog("Couldn't create item \"%s\", screen item limit reached\n", item_string[ID]);
22053 }
22054 22444 }
22055
22056 3530 void do_createnpc(const bool v)
22057 {
22058 3530 const int32_t ID = SH::get_arg(sarg1, v) / 10000;
22059
22060
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3530 times.
3530 if(BC::checkGuyID(ID) != SH::_NoError)
22061 return;
22062
22063 //If we make a segmented enemy there'll be more than one sprite created
22064 3530 word numcreated = addenemy(ri->screenref, 0, 0, ID, -10);
22065
22066
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3530 times.
3530 if(numcreated == 0)
22067 {
22068 //ri->guyref = MAX_DWORD;
22069 ri->guyref = 0;
22070 Z_scripterrlog("Couldn't create NPC \"%s\", screen NPC limit reached\n", guy_string[ID]);
22071 }
22072 else
22073 {
22074 3530 word index = guys.Count() - numcreated; //Get the main enemy, not a segment
22075 3530 ri->guyref = guys.spr(index)->getUID();
22076
22077
2/2
✓ Branch 0 taken 3566 times.
✓ Branch 1 taken 3530 times.
7096 for(; index<guys.Count(); index++)
22078 3566 ((enemy*)guys.spr(index))->script_spawned=true;
22079
22080 3530 Z_eventlog("Script created NPC \"%s\" with UID = %ld\n", guy_string[ID], ri->guyref);
22081 }
22082 3530 }
22083
22084 ///----------------------------------------------------------------------------------------------------//
22085 //Drawing & Sound
22086
22087 1117 void do_message(const bool v)
22088 {
22089 1117 const int32_t ID = SH::get_arg(sarg1, v) / 10000;
22090
22091
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1117 times.
1117 if(BC::checkMessage(ID) != SH::_NoError)
22092 return;
22093
22094
2/2
✓ Branch 0 taken 302 times.
✓ Branch 1 taken 815 times.
1117 if(ID == 0)
22095 {
22096 302 dismissmsg();
22097 302 msgfont = get_zc_font(font_zfont);
22098 302 blockpath = false;
22099 302 Hero.finishedmsg();
22100 302 }
22101 else
22102 815 donewmsg(get_scr(ri->screenref), ID);
22103 1117 }
22104
22105 45275698 INLINE void set_drawing_command_args(const int32_t j, const word numargs)
22106 {
22107
1/2
✓ Branch 0 taken 45275698 times.
✗ Branch 1 not taken.
45275698 assert(numargs <= DRAWCMD_MAX_ARG_COUNT);
22108
2/2
✓ Branch 0 taken 368858404 times.
✓ Branch 1 taken 45275698 times.
414134102 for(int32_t k = 1; k <= numargs; k++)
22109 368858404 script_drawing_commands[j][k] = SH::read_stack(ri->sp + (numargs - k));
22110 45275698 }
22111
22112 53711106 INLINE void set_user_bitmap_command_args(const int32_t j, const word numargs)
22113 {
22114
1/2
✓ Branch 0 taken 53711106 times.
✗ Branch 1 not taken.
53711106 assert(numargs <= DRAWCMD_MAX_ARG_COUNT);
22115 //ri->bitmapref = SH::read_stack(ri->sp+numargs);
22116
2/2
✓ Branch 0 taken 326059206 times.
✓ Branch 1 taken 53711106 times.
379770312 for(int32_t k = 1; k <= numargs; k++)
22117 326059206 script_drawing_commands[j][k] = SH::read_stack(ri->sp + (numargs - k));
22118 53711106 }
22119
22120 98985724 static DrawOrigin get_draw_origin_for_screen_draw_command()
22121 {
22122 98985724 DrawOrigin draw_origin = ri->screen_draw_origin;
22123
22124
2/2
✓ Branch 0 taken 121364 times.
✓ Branch 1 taken 98864360 times.
98985724 if (draw_origin == DrawOrigin::Default)
22125 {
22126
4/4
✓ Branch 0 taken 8256 times.
✓ Branch 1 taken 98856104 times.
✓ Branch 2 taken 94944009 times.
✓ Branch 3 taken 3912095 times.
98864360 bool in_scrolling_region = is_in_scrolling_region() || (screenscrolling && scrolling_region.screen_count > 1);
22127 98864360 draw_origin = in_scrolling_region ? DrawOrigin::Region : DrawOrigin::PlayingField;
22128 98864360 }
22129
2/2
✓ Branch 0 taken 46076 times.
✓ Branch 1 taken 98939648 times.
98985724 if (draw_origin == DrawOrigin::Region)
22130 {
22131
2/2
✓ Branch 0 taken 38992 times.
✓ Branch 1 taken 7084 times.
46076 if (scrolling_using_new_region_coords)
22132 7084 draw_origin = DrawOrigin::RegionScrollingNew;
22133 46076 }
22134
2/2
✓ Branch 0 taken 1484 times.
✓ Branch 1 taken 98938164 times.
98939648 else if (draw_origin == DrawOrigin::RegionScrollingOld)
22135 {
22136 1484 draw_origin = DrawOrigin::Region;
22137 1484 }
22138
2/2
✓ Branch 0 taken 98937176 times.
✓ Branch 1 taken 988 times.
98938164 else if (draw_origin == DrawOrigin::RegionScrollingNew)
22139 {
22140
1/2
✓ Branch 0 taken 988 times.
✗ Branch 1 not taken.
988 if (!screenscrolling)
22141 draw_origin = DrawOrigin::Region;
22142 988 }
22143
22144 98985724 return draw_origin;
22145 }
22146
22147 1440 static DrawOrigin get_draw_origin_for_bitmap_draw_command()
22148 {
22149 1440 return DrawOrigin::Screen;
22150 }
22151
22152 98987164 static std::pair<DrawOrigin, int> get_draw_origin_for_draw_command(bool is_screen_draw, int scripting_bitmap_id)
22153 {
22154
2/2
✓ Branch 0 taken 98985364 times.
✓ Branch 1 taken 1800 times.
98987164 if (get_qr(qr_BROKEN_SCRIPTS_BITMAP_DRAW_ORIGIN))
22155 98985364 return {get_draw_origin_for_screen_draw_command(), ri->screen_draw_origin_target};
22156
22157 1800 auto [bitmap_id, _] = resolveScriptingBitmapId(scripting_bitmap_id);
22158
22159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1800 times.
1800 if (FFCore.doesResolveToDeprecatedSystemBitmap(bitmap_id))
22160 return {DrawOrigin::Screen, 0};
22161
22162
2/2
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 1440 times.
1800 if (FFCore.doesResolveToScreenBitmap(bitmap_id))
22163 360 return {get_draw_origin_for_screen_draw_command(), ri->screen_draw_origin_target};
22164
22165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1440 times.
1440 if (!is_screen_draw)
22166 1440 return {get_draw_origin_for_bitmap_draw_command(), 0};
22167
22168 return {DrawOrigin::Screen, 0};
22169 98987164 }
22170
22171 98986804 static void do_drawing_command(int32_t script_command, bool is_screen_draw)
22172 {
22173
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98986804 times.
98986804 if (FFCore.skipscriptdraws)
22174 return;
22175
22176 98986804 int32_t j = script_drawing_commands.GetNext();
22177
1/2
✓ Branch 0 taken 98986804 times.
✗ Branch 1 not taken.
98986804 if(j == -1) //out of drawing command space
22178 {
22179 Z_scripterrlog("Max draw primitive limit reached\n");
22180 return;
22181 }
22182
22183 98986804 script_drawing_commands[j] = {};
22184 98986804 script_drawing_commands[j][0] = script_command;
22185 98986804 script_drawing_commands[j][DRAWCMD_CURRENT_TARGET] = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
22186
22187
39/81
✓ Branch 0 taken 2428096 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1096118 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 383247 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2698101 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 900326 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 49606 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 321769 times.
✓ Branch 13 taken 3150 times.
✓ Branch 14 taken 26528 times.
✓ Branch 15 taken 148823 times.
✓ Branch 16 taken 144 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 824 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 167318 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 1173 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✓ Branch 29 taken 19821648 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 906 times.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✓ Branch 34 taken 2051 times.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 37 taken 7323 times.
✗ Branch 38 not taken.
✓ Branch 39 taken 1850 times.
✓ Branch 40 taken 2356839 times.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✓ Branch 45 taken 1080 times.
✓ Branch 46 taken 1527166 times.
✓ Branch 47 taken 5152881 times.
✓ Branch 48 taken 21691969 times.
✓ Branch 49 taken 963845 times.
✓ Branch 50 taken 148476 times.
✗ Branch 51 not taken.
✓ Branch 52 taken 9270 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 4137125 times.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✓ Branch 57 taken 1568537 times.
✓ Branch 58 taken 161166 times.
✓ Branch 59 taken 7971 times.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✓ Branch 64 taken 502 times.
✓ Branch 65 taken 80910 times.
✓ Branch 66 taken 59561 times.
✓ Branch 67 taken 32636464 times.
✗ Branch 68 not taken.
✓ Branch 69 taken 865 times.
✓ Branch 70 taken 45504 times.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✓ Branch 74 taken 264343 times.
✓ Branch 75 taken 113329 times.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
98986804 switch(script_command)
22188 {
22189 case RECTR:
22190 2428096 set_drawing_command_args(j, 12);
22191 2428096 break;
22192
22193 case FRAMER:
22194 set_drawing_command_args(j, 9);
22195 break;
22196
22197 case CIRCLER:
22198 1096118 set_drawing_command_args(j, 11);
22199 1096118 break;
22200
22201 case ARCR:
22202 set_drawing_command_args(j, 14);
22203 break;
22204
22205 case ELLIPSER:
22206 1850 set_drawing_command_args(j, 12);
22207 1850 break;
22208
22209 case LINER:
22210 2356839 set_drawing_command_args(j, 11);
22211 2356839 break;
22212
22213 case PUTPIXELR:
22214 383247 set_drawing_command_args(j, 8);
22215 383247 break;
22216
22217 case PIXELARRAYR:
22218 {
22219 set_drawing_command_args(j, 5);
22220 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22221
22222 int32_t arrayptr = script_drawing_commands[j][2];
22223 if ( !arrayptr ) //Don't crash because of vector size.
22224 {
22225 Z_scripterrlog("Invalid array pointer %d passed to Screen->PutPixels(). Aborting.", arrayptr);
22226 break;
22227 }
22228 int32_t sz = ArrayH::getSize(arrayptr);
22229 if(!sz)
22230 {
22231 script_drawing_commands.PopLast();
22232 return;
22233 }
22234 v->resize(sz, 0);
22235 int32_t* pos = &v->at(0);
22236
22237 ArrayH::getValues(script_drawing_commands[j][2], pos, sz);
22238 script_drawing_commands[j].SetVector(v);
22239 break;
22240 }
22241
22242 case TILEARRAYR:
22243 {
22244 set_drawing_command_args(j, 2);
22245 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22246
22247 int32_t arrayptr = script_drawing_commands[j][2];
22248 if ( !arrayptr ) //Don't crash because of vector size.
22249 {
22250 Z_scripterrlog("Invalid array pointer %d passed to Screen->DrawTiles(). Aborting.", arrayptr);
22251 break;
22252 }
22253 int32_t sz = ArrayH::getSize(arrayptr);
22254 if(!sz)
22255 {
22256 script_drawing_commands.PopLast();
22257 return;
22258 }
22259 v->resize(sz, 0);
22260 int32_t* pos = &v->at(0);
22261
22262 ArrayH::getValues(script_drawing_commands[j][2], pos, sz);
22263 script_drawing_commands[j].SetVector(v);
22264 break;
22265 }
22266
22267 case LINESARRAY:
22268 {
22269 set_drawing_command_args(j, 2);
22270 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22271
22272 int32_t arrayptr = script_drawing_commands[j][2];
22273 if ( !arrayptr ) //Don't crash because of vector size.
22274 {
22275 Z_scripterrlog("Invalid array pointer %d passed to Screen->Lines(). Aborting.", arrayptr);
22276 break;
22277 }
22278 int32_t sz = ArrayH::getSize(arrayptr);
22279 if(!sz)
22280 {
22281 script_drawing_commands.PopLast();
22282 return;
22283 }
22284 v->resize(sz, 0);
22285 int32_t* pos = &v->at(0);
22286
22287 ArrayH::getValues(script_drawing_commands[j][2], pos, sz);
22288 script_drawing_commands[j].SetVector(v);
22289 break;
22290 }
22291
22292 case COMBOARRAYR:
22293 {
22294 set_drawing_command_args(j, 2);
22295 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22296 int32_t arrayptr = script_drawing_commands[j][2];
22297 if ( !arrayptr ) //Don't crash because of vector size.
22298 {
22299 Z_scripterrlog("Invalid array pointer %d passed to Screen->DrawCombos(). Aborting.", arrayptr);
22300 break;
22301 }
22302 int32_t sz = ArrayH::getSize(arrayptr);
22303 if(!sz)
22304 {
22305 script_drawing_commands.PopLast();
22306 return;
22307 }
22308 v->resize(sz, 0);
22309 int32_t* pos = &v->at(0);
22310
22311 ArrayH::getValues(script_drawing_commands[j][2], pos, sz);
22312 script_drawing_commands[j].SetVector(v);
22313 break;
22314 }
22315 case POLYGONR:
22316 {
22317 1080 set_drawing_command_args(j, 5);
22318
22319 1080 int32_t arrayptr = script_drawing_commands[j][3];
22320
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if ( !arrayptr ) //Don't crash because of vector size.
22321 {
22322 Z_scripterrlog("Invalid array pointer %d passed to Screen->Polygon(). Aborting.", arrayptr);
22323 break;
22324 }
22325 1080 int32_t sz = ArrayH::getSize(arrayptr);
22326
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if(!sz)
22327 {
22328 script_drawing_commands.PopLast();
22329 return;
22330 }
22331
22332 1080 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22333 1080 v->resize(sz, 0);
22334
22335 1080 int32_t* pos = &v->at(0);
22336
22337
22338 1080 ArrayH::getValues(script_drawing_commands[j][3], pos, sz);
22339 1080 script_drawing_commands[j].SetVector(v);
22340 }
22341 1080 break;
22342
22343 case DRAWTILER:
22344 1527166 set_drawing_command_args(j, 15);
22345 1527166 break;
22346
22347 case DRAWTILECLOAKEDR:
22348 set_drawing_command_args(j, 7);
22349 break;
22350
22351 case DRAWCOMBOR:
22352 2698101 set_drawing_command_args(j, 16);
22353 2698101 break;
22354
22355 case DRAWCOMBOCLOAKEDR:
22356 set_drawing_command_args(j, 7);
22357 break;
22358
22359 case FASTTILER:
22360 5152881 set_drawing_command_args(j, 6);
22361 5152881 break;
22362
22363 case FASTCOMBOR:
22364 21691969 set_drawing_command_args(j, 6);
22365 21691969 break;
22366
22367 case DRAWCHARR:
22368 963845 set_drawing_command_args(j, 10);
22369 963845 break;
22370
22371 case DRAWINTR:
22372 148476 set_drawing_command_args(j, 11);
22373 148476 break;
22374
22375 case SPLINER:
22376 set_drawing_command_args(j, 11);
22377 break;
22378
22379 case QUADR:
22380 9270 set_drawing_command_args(j, 15);
22381 9270 break;
22382
22383 case TRIANGLER:
22384 set_drawing_command_args(j, 13);
22385 break;
22386
22387 case BITMAPR:
22388 900326 set_drawing_command_args(j, 12);
22389 900326 break;
22390
22391 case BITMAPEXR:
22392 set_drawing_command_args(j, 16);
22393 break;
22394
22395 case DRAWLAYERR:
22396 4137125 set_drawing_command_args(j, 8);
22397 4137125 break;
22398
22399 case DRAWSCREENR:
22400 49606 set_drawing_command_args(j, 6);
22401 49606 break;
22402
22403 case QUAD3DR:
22404 {
22405 set_drawing_command_args(j, 8);
22406 int32_t arrayptr = script_drawing_commands[j][2];
22407 int32_t sz = ArrayH::getSize(arrayptr);
22408 arrayptr = script_drawing_commands[j][3];
22409 sz += ArrayH::getSize(arrayptr);
22410 arrayptr = script_drawing_commands[j][4];
22411 sz += ArrayH::getSize(arrayptr);
22412 arrayptr = script_drawing_commands[j][5];
22413 sz += ArrayH::getSize(arrayptr);
22414 if(sz < 25)
22415 {
22416 script_drawing_commands.PopLast();
22417 return;
22418 }
22419 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22420 v->resize(sz, 0);
22421
22422 int32_t* pos = &v->at(0);
22423 int32_t* uv = &v->at(12);
22424 int32_t* col = &v->at(20);
22425 int32_t* size = &v->at(24);
22426
22427 ArrayH::getValues((script_drawing_commands[j][2]), pos, 12);
22428 ArrayH::getValues((script_drawing_commands[j][3]), uv, 8);
22429 ArrayH::getValues((script_drawing_commands[j][4]), col, 4);
22430 //FFCore.getValues2(script_drawing_commands[j][5], size, 2);
22431 ArrayH::getValues((script_drawing_commands[j][5]), size, 2);
22432
22433 script_drawing_commands[j].SetVector(v);
22434 }
22435 break;
22436
22437 case TRIANGLE3DR:
22438 {
22439 set_drawing_command_args(j, 8);
22440
22441 int32_t arrayptr = script_drawing_commands[j][2];
22442 int32_t sz = ArrayH::getSize(arrayptr);
22443 arrayptr = script_drawing_commands[j][3];
22444 sz += ArrayH::getSize(arrayptr);
22445 arrayptr = script_drawing_commands[j][4];
22446 sz += ArrayH::getSize(arrayptr);
22447 arrayptr = script_drawing_commands[j][5];
22448 sz += ArrayH::getSize(arrayptr);
22449 if(sz < 19)
22450 {
22451 script_drawing_commands.PopLast();
22452 return;
22453 }
22454
22455 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22456 v->resize(sz, 0);
22457
22458 int32_t* pos = &v->at(0);
22459 int32_t* uv = &v->at(9);
22460 int32_t* col = &v->at(15);
22461 int32_t* size = &v->at(18);
22462
22463 ArrayH::getValues(script_drawing_commands[j][2], pos, 8);
22464 ArrayH::getValues(script_drawing_commands[j][3], uv, 6);
22465 ArrayH::getValues(script_drawing_commands[j][4], col, 3);
22466 ArrayH::getValues(script_drawing_commands[j][5], size, 2);
22467
22468 script_drawing_commands[j].SetVector(v);
22469 }
22470 break;
22471
22472 case DRAWSTRINGR:
22473 {
22474 1568537 set_drawing_command_args(j, 9);
22475 // Unused
22476 //const int32_t index = script_drawing_commands[j][19] = j;
22477
22478 1568537 string *str = script_drawing_commands.GetString();
22479 1568537 ArrayH::getString(script_drawing_commands[j][8], *str, 256);
22480 1568537 script_drawing_commands[j].SetString(str);
22481 }
22482 1568537 break;
22483
22484 case DRAWSTRINGR2:
22485 {
22486 161166 set_drawing_command_args(j, 11);
22487 // Unused
22488 //const int32_t index = script_drawing_commands[j][19] = j;
22489
22490 161166 string *str = script_drawing_commands.GetString();
22491 161166 ArrayH::getString(script_drawing_commands[j][8], *str, 256);
22492 161166 script_drawing_commands[j].SetString(str);
22493 }
22494 161166 break;
22495
22496 case BMPRECTR:
22497 7971 set_user_bitmap_command_args(j, 12); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+12);
22498 //Pop the args off the stack first. Then pop the pointer and push it to sdci[17].
22499 //The pointer for the bitmap variable (its literal value) is always ri->sp+numargs, so, with 12 args, it is sp+12.
22500 7971 break;
22501
22502 case BMPFRAMER:
22503 set_user_bitmap_command_args(j, 9);
22504 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+9);
22505 break;
22506
22507 case CLEARBITMAP:
22508 {
22509 321769 set_user_bitmap_command_args(j, 1);
22510 321769 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+1);
22511 321769 break;
22512 }
22513 case BITMAPCLEARTOCOLOR:
22514 {
22515 3150 set_user_bitmap_command_args(j, 2);
22516 3150 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+2);
22517 3150 break;
22518 }
22519 case REGENERATEBITMAP:
22520 {
22521 26528 set_user_bitmap_command_args(j, 3);
22522 26528 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+3);
22523 26528 break;
22524 }
22525 case BMPPOLYGONR:
22526 {
22527 set_user_bitmap_command_args(j, 5);
22528 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+5);
22529 int32_t arrayptr = script_drawing_commands[j][3];
22530 if ( !arrayptr ) //Don't crash because of vector size.
22531 {
22532 Z_scripterrlog("Invalid array pointer %d passed to Screen->Polygon(). Aborting.", arrayptr);
22533 break;
22534 }
22535 int32_t sz = ArrayH::getSize(arrayptr);
22536 if(!sz)
22537 {
22538 script_drawing_commands.PopLast();
22539 return;
22540 }
22541 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22542 v->resize(sz, 0);
22543
22544 int32_t* pos = &v->at(0);
22545
22546
22547 ArrayH::getValues(script_drawing_commands[j][3], pos, sz);
22548 script_drawing_commands[j].SetVector(v);
22549 }
22550 break;
22551 case READBITMAP:
22552 {
22553 set_user_bitmap_command_args(j, 2);
22554 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+2);
22555 string& user_path = *script_drawing_commands.GetString();
22556 ArrayH::getString(script_drawing_commands[j][2], user_path, 256);
22557
22558 if (get_qr(qr_BITMAP_AND_FILESYSTEM_PATHS_ALWAYS_RELATIVE))
22559 {
22560 if (auto r = parse_user_path(user_path, true); !r)
22561 {
22562 scripting_log_error_with_context("Error: {}", r.error());
22563 return;
22564 } else user_path = r.value();
22565 }
22566 else
22567 {
22568 regulate_path(user_path);
22569 }
22570
22571 script_drawing_commands[j].SetString(&user_path);
22572 break;
22573 }
22574 case WRITEBITMAP:
22575 {
22576 set_user_bitmap_command_args(j, 3);
22577 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+3);
22578 std::string& user_path = *script_drawing_commands.GetString();
22579 ArrayH::getString(script_drawing_commands[j][2], user_path, 256);
22580
22581 if (get_qr(qr_BITMAP_AND_FILESYSTEM_PATHS_ALWAYS_RELATIVE))
22582 {
22583 if (auto r = parse_user_path(user_path, true); !r)
22584 {
22585 scripting_log_error_with_context("Error: {}", r.error());
22586 return;
22587 } else user_path = r.value();
22588 }
22589 else
22590 {
22591 regulate_path(user_path);
22592 }
22593
22594 script_drawing_commands[j].SetString(&user_path);
22595 break;
22596 }
22597
22598 148823 case BMPCIRCLER: set_user_bitmap_command_args(j, 11); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+11); break;
22599 case BMPARCR: set_user_bitmap_command_args(j, 14); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+14); break;
22600 502 case BMPELLIPSER: set_user_bitmap_command_args(j, 12); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+12); break;
22601 144 case BMPLINER: set_user_bitmap_command_args(j, 11); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+11); break;
22602 case BMPSPLINER: set_user_bitmap_command_args(j, 11); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+11); break;
22603 80910 case BMPPUTPIXELR: set_user_bitmap_command_args(j, 8); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+8); break;
22604 59561 case BMPDRAWTILER: set_user_bitmap_command_args(j, 15); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+15); break;
22605 case BMPDRAWTILECLOAKEDR: set_user_bitmap_command_args(j, 7); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+7); break;
22606 824 case BMPDRAWCOMBOR: set_user_bitmap_command_args(j, 16); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+16); break;
22607 case BMPDRAWCOMBOCLOAKEDR: set_user_bitmap_command_args(j, 7); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+7); break;
22608 167318 case BMPFASTTILER: set_user_bitmap_command_args(j, 6); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+6); break;
22609 32636464 case BMPFASTCOMBOR: set_user_bitmap_command_args(j, 6); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+6); break;
22610 case BMPDRAWCHARR: set_user_bitmap_command_args(j, 10); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+10); break;
22611 case BMPDRAWINTR: set_user_bitmap_command_args(j, 11); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+11); break;
22612 case BMPDRAWSTRINGR:
22613 {
22614 865 set_user_bitmap_command_args(j, 9);
22615 865 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+9);
22616 // Unused
22617 //const int32_t index = script_drawing_commands[j][19] = j;
22618
22619 865 string *str = script_drawing_commands.GetString();
22620 865 ArrayH::getString(script_drawing_commands[j][8], *str, 256);
22621 865 script_drawing_commands[j].SetString(str);
22622
22623 }
22624 865 break;
22625 case BMPDRAWSTRINGR2:
22626 {
22627 45504 set_user_bitmap_command_args(j, 11);
22628 45504 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+11);
22629 // Unused
22630 //const int32_t index = script_drawing_commands[j][19] = j;
22631
22632 45504 string *str = script_drawing_commands.GetString();
22633 45504 ArrayH::getString(script_drawing_commands[j][8], *str, 256);
22634 45504 script_drawing_commands[j].SetString(str);
22635
22636 }
22637 45504 break;
22638 case BMPQUADR: set_user_bitmap_command_args(j, 16); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+16); break;
22639 case BMPQUAD3DR:
22640 {
22641 set_drawing_command_args(j, 9);
22642 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22643 v->resize(26, 0);
22644
22645 int32_t* pos = &v->at(0);
22646 int32_t* uv = &v->at(12);
22647 int32_t* col = &v->at(20);
22648 int32_t* size = &v->at(24);
22649
22650
22651 ArrayH::getValues(script_drawing_commands[j][2], pos, 12);
22652 ArrayH::getValues(script_drawing_commands[j][3], uv, 8);
22653 ArrayH::getValues(script_drawing_commands[j][4], col, 4);
22654 ArrayH::getValues(script_drawing_commands[j][5], size, 2);
22655
22656 script_drawing_commands[j].SetVector(v);
22657 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+9);
22658
22659 }
22660 break;
22661 case BMPTRIANGLER: set_user_bitmap_command_args(j, 14); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+14); break;
22662 case BMPTRIANGLE3DR:
22663 {
22664 set_drawing_command_args(j, 9);
22665
22666 std::vector<int32_t> *v = script_drawing_commands.GetVector();
22667 v->resize(20, 0);
22668
22669 int32_t* pos = &v->at(0);
22670 int32_t* uv = &v->at(9);
22671 int32_t* col = &v->at(15);
22672 int32_t* size = &v->at(18);
22673
22674
22675 ArrayH::getValues(script_drawing_commands[j][2], pos, 8);
22676 ArrayH::getValues(script_drawing_commands[j][3], uv, 6);
22677 ArrayH::getValues(script_drawing_commands[j][4], col, 3);
22678 ArrayH::getValues(script_drawing_commands[j][5], size, 2);
22679
22680 script_drawing_commands[j].SetVector(v);
22681 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+9);
22682 break;
22683 }
22684
22685 case BMPDRAWLAYERR:
22686 1173 set_user_bitmap_command_args(j, 8);
22687 1173 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+8);
22688 1173 break;
22689 case BMPDRAWLAYERSOLIDR:
22690 case BMPDRAWLAYERCFLAGR:
22691 case BMPDRAWLAYERCTYPER:
22692 case BMPDRAWLAYERCIFLAGR:
22693 case BMPDRAWLAYERSOLIDITYR: set_user_bitmap_command_args(j, 9); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+9); break;
22694 case BMPDRAWSCREENR:
22695 case BMPDRAWSCREENSOLIDR:
22696 case BMPDRAWSCREENSOLID2R:
22697 case BMPDRAWSCREENCOMBOFR:
22698 case BMPDRAWSCREENCOMBOIR:
22699 case BMPDRAWSCREENCOMBOTR:
22700 2051 set_user_bitmap_command_args(j, 6); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+6); break;
22701 case BITMAPGETPIXEL:
22702 {
22703 set_user_bitmap_command_args(j, 3); script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+3);
22704 break;
22705 }
22706 case BMPBLIT:
22707 {
22708 264343 set_user_bitmap_command_args(j, 16);
22709
22710 264343 int bmp_target = SH::read_stack(ri->sp+16);
22711 264343 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = bmp_target;
22712
22713
2/2
✓ Branch 0 taken 263983 times.
✓ Branch 1 taken 360 times.
264343 if (!get_qr(qr_BROKEN_SCRIPTS_BITMAP_DRAW_ORIGIN))
22714 {
22715 360 int bmp_dest = script_drawing_commands[j][2];
22716 720 auto [draw_origin, draw_origin_target] = get_draw_origin_for_draw_command(is_screen_draw, bmp_dest);
22717 360 script_drawing_commands[j].secondary_draw_origin = draw_origin;
22718 360 script_drawing_commands[j].secondary_draw_origin_target = draw_origin_target;
22719 360 }
22720 264343 break;
22721 }
22722 case BMPBLITTO:
22723 {
22724 113329 set_user_bitmap_command_args(j, 16);
22725 113329 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+16);
22726
22727
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if (!get_qr(qr_BROKEN_SCRIPTS_BITMAP_DRAW_ORIGIN))
22728 {
22729 int bmp_source = script_drawing_commands[j][2];
22730 auto [draw_origin, draw_origin_target] = get_draw_origin_for_draw_command(is_screen_draw, bmp_source);
22731 script_drawing_commands[j].secondary_draw_origin = draw_origin;
22732 script_drawing_commands[j].secondary_draw_origin_target = draw_origin_target;
22733 }
22734 113329 break;
22735 }
22736 case TILEBLIT:
22737 {
22738 set_drawing_command_args(j, 17);
22739 break;
22740 }
22741 case COMBOBLIT:
22742 {
22743 set_drawing_command_args(j, 17);
22744 break;
22745 }
22746 case BMPTILEBLIT:
22747 {
22748 set_user_bitmap_command_args(j, 17);
22749 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+17);
22750 break;
22751 }
22752 case BMPCOMBOBLIT:
22753 {
22754 set_user_bitmap_command_args(j, 17);
22755 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+17);
22756 break;
22757 }
22758 case BMPMODE7:
22759 {
22760 set_user_bitmap_command_args(j, 13);
22761 //for(int32_t q = 0; q < 8; ++q )
22762 //Z_scripterrlog("FFscript blit() ri->d[%d] is: %d\n", q, ri->d[q]);
22763 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+13);
22764 break;
22765 }
22766
22767 case BMPWRITETILE:
22768 {
22769 19821648 set_user_bitmap_command_args(j, 6);
22770 19821648 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+6);
22771 19821648 break;
22772 }
22773 case BMPDITHER:
22774 {
22775 set_user_bitmap_command_args(j, 5);
22776 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+5);
22777 break;
22778 }
22779 case BMPMASKDRAW:
22780 {
22781 906 set_user_bitmap_command_args(j, 3);
22782 906 script_drawing_commands[j][4] = 0x01 * 10000L;
22783 906 script_drawing_commands[j][5] = 0xFF * 10000L;
22784 906 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+3);
22785 906 break;
22786 }
22787 case BMPMASKDRAW2:
22788 {
22789 set_user_bitmap_command_args(j, 4);
22790 script_drawing_commands[j][5] = script_drawing_commands[j][4];
22791 script_drawing_commands[j][0] = BMPMASKDRAW;
22792 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+4);
22793 break;
22794 }
22795 case BMPMASKDRAW3:
22796 {
22797 set_user_bitmap_command_args(j, 5);
22798 script_drawing_commands[j][0] = BMPMASKDRAW;
22799 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+5);
22800 break;
22801 }
22802 case BMPMASKBLIT:
22803 {
22804 set_user_bitmap_command_args(j, 4);
22805 script_drawing_commands[j][5] = 0x01 * 10000L;
22806 script_drawing_commands[j][6] = 0xFF * 10000L;
22807 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+4);
22808 break;
22809 }
22810 case BMPMASKBLIT2:
22811 {
22812 set_user_bitmap_command_args(j, 5);
22813 script_drawing_commands[j][6] = script_drawing_commands[j][5];
22814 script_drawing_commands[j][0] = BMPMASKBLIT;
22815 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+5);
22816 break;
22817 }
22818 case BMPMASKBLIT3:
22819 {
22820 set_user_bitmap_command_args(j, 6);
22821 script_drawing_commands[j][0] = BMPMASKBLIT;
22822 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+6);
22823 break;
22824 }
22825 case BMPREPLCOLOR:
22826 case BMPSHIFTCOLOR:
22827 {
22828 7323 set_user_bitmap_command_args(j, 4);
22829 7323 script_drawing_commands[j][DRAWCMD_BMP_TARGET] = SH::read_stack(ri->sp+4);
22830 7323 break;
22831 }
22832
22833 case DRAWLIGHT_CONE:
22834 case DRAWLIGHT_CIRCLE:
22835 case DRAWLIGHT_SQUARE:
22836 {
22837 // These draw commands implicitly draw at the SPLAYER_DARKROOM_UNDER timing.
22838 // Shift the given args up by one.
22839 int num_args = script_command == DRAWLIGHT_CONE ? 8 : 7;
22840 set_drawing_command_args(j, num_args);
22841 for (int i = num_args; i >= 1; i--)
22842 script_drawing_commands[j][i + 1] = script_drawing_commands[j][i];
22843 script_drawing_commands[j][1] = SPLAYER_DARKROOM_UNDER * 10000;
22844 break;
22845 }
22846 }
22847
22848 int bmp_target;
22849
2/2
✓ Branch 0 taken 45321202 times.
✓ Branch 1 taken 53665602 times.
98986804 if (is_screen_draw)
22850 45321202 bmp_target = zscriptDrawingRenderTarget->GetCurrentRenderTarget() + 10;
22851 else
22852 53665602 bmp_target = script_drawing_commands[j][DRAWCMD_BMP_TARGET];
22853
22854 197973608 auto [draw_origin, draw_origin_target] = get_draw_origin_for_draw_command(is_screen_draw, bmp_target);
22855 98986804 script_drawing_commands[j].draw_origin = draw_origin;
22856 98986804 script_drawing_commands[j].draw_origin_target = draw_origin_target;
22857
22858 98986804 script_drawing_commands.mark_dirty(script_drawing_commands[j][1]/10000);
22859 98986804 }
22860
22861 7069332 void do_set_rendertarget(bool)
22862 {
22863 7069332 int32_t target = int32_t(SH::read_stack(ri->sp) / 10000);
22864 7069332 zscriptDrawingRenderTarget->SetCurrentRenderTarget(target);
22865 7069332 }
22866
22867 339164 void do_sfx(const bool v)
22868 {
22869 339164 int32_t ID = SH::get_arg(sarg1, v) / 10000;
22870
22871
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 339160 times.
339164 if(BC::checkSFXID(ID) != SH::_NoError)
22872 4 return;
22873
22874 339160 sfx(ID);
22875 339164 }
22876
22877 14 void do_sfx_ex(const bool restart)
22878 {
22879 14 int32_t ID = SH::read_stack(ri->sp + 4) / 10000;
22880 14 int32_t vol = vbound(SH::read_stack(ri->sp + 3), 0, 10000 * 100);
22881 14 int32_t pan = vbound(SH::read_stack(ri->sp + 2)/10000 + 128, 0, 255);
22882 14 int32_t freq = SH::read_stack(ri->sp + 1);
22883 14 bool loop = SH::read_stack(ri->sp) / 10000;
22884
22885
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (BC::checkSFXID(ID) != SH::_NoError)
22886 return;
22887
22888
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14 if (!restart && !sfx_allocated(ID))
22889 return;
22890
22891 14 sfx(ID, pan, loop, restart, vol, freq);
22892 14 }
22893
22894 static int get_sfx_completion()
22895 {
22896 int32_t ID = get_register(sarg1) / 10000;
22897
22898 if (!sfx_allocated(ID))
22899 {
22900 return -10000;
22901 }
22902
22903 int sample_pos = voice_get_position(sfx_voice[ID]);
22904 if (sample_pos < 0)
22905 {
22906 return -10000;
22907 }
22908
22909 uint32_t sample_length = sfx_get_length(ID);
22910 uint64_t res = ((uint64_t)sample_pos * 10000 * 100) / sample_length;
22911 return int32_t(res);
22912 }
22913
22914 void do_get_sfx_completion()
22915 {
22916 int32_t ID = get_register(sarg1) / 10000;
22917 if (replay_is_active())
22918 replay_step_comment(fmt::format("ID {}", ID));
22919 int32_t value = replay_get_state(ReplayStateType::SfxPosition, get_sfx_completion);
22920 set_register(sarg1, value);
22921 }
22922
22923 void FFScript::AlloffLimited(int32_t flagset)
22924 {
22925 clear_bitmap(msg_txt_display_buf);
22926 clear_bitmap(msg_bg_display_buf);
22927 clear_bitmap(msg_portrait_display_buf);
22928 set_clip_state(msg_txt_display_buf, 1);
22929 set_clip_state(msg_bg_display_buf, 1);
22930 set_clip_state(msg_portrait_display_buf, 1);
22931
22932
22933 clear_bitmap(pricesdisplaybuf);
22934 set_clip_state(pricesdisplaybuf, 1);
22935
22936 if(items.idCount(iPile))
22937 {
22938 loadlvlpal(DMaps[cur_dmap].color);
22939 }
22940
22941 /*
22942
22943 #define warpFlagCLEARITEMS 0x200
22944 #define warpFlagCLEARGUYS 0x400
22945 #define warpFlagCLEARLWEAPONS 0x800
22946 #define warpFlagCLEAREWEAPONS 0x1000
22947 #define warpFlagCLEARHOOKSHOT 0x2000
22948 #define warpFlagCLEARDECORATIONS 0x4000
22949 #define warpFlagCLEARPARTICLES 0x8000
22950 */
22951
22952 if ( (flagset&warpFlagCLEARITEMS) ) items.clear();
22953 if ( (flagset&warpFlagCLEARGUYS) ) guys.clear();
22954 if ( (flagset&warpFlagCLEARLWEAPONS) ) Lwpns.clear();
22955 if ( (flagset&warpFlagCLEAREWEAPONS) ) Ewpns.clear();
22956 if ( (flagset&warpFlagCLEARHOOKSHOT) )
22957 {
22958 chainlinks.clear();
22959 Hero.reset_hookshot();
22960 }
22961 if ( (flagset&warpFlagCLEARDECORATIONS) ) decorations.clear();
22962 if ( (flagset&warpFlagCLEARPARTICLES) ) particles.clear();
22963 clearScriptHelperData();
22964
22965
22966
22967 clearScriptHelperData();
22968
22969 lensclk = 0;
22970 lensid=-1;
22971 drawguys=true;
22972 down_control_states[btnUp] =
22973 down_control_states[btnDown] =
22974 down_control_states[btnLeft] =
22975 down_control_states[btnRight] =
22976 down_control_states[btnA] =
22977 down_control_states[btnB] =
22978 down_control_states[btnS] = true;
22979
22980 if(watch && !cheat_superman)
22981 {
22982 Hero.setClock(false);
22983 }
22984
22985 watch=freeze_guys=loaded_guys=blockpath=false;
22986
22987 activation_counters.clear();
22988 activation_counters_ffc.clear();
22989 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
22990 get_screen_state(scr->screen).loaded_enemies = false;
22991 });
22992
22993 sle_clk=0;
22994
22995 if(usebombpal)
22996 {
22997 memcpy(RAMpal, tempbombpal, PAL_SIZE*sizeof(RGB));
22998 refreshpal=true;
22999 usebombpal=false;
23000 }
23001
23002
23003 }
23004
23005 188 void doWarpEffect(int32_t warpEffect, bool out)
23006 {
23007
3/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 156 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
✓ Branch 5 taken 8 times.
188 switch(warpEffect)
23008 {
23009 case warpEffectZap:
23010 if(out) zapout();
23011 else zapin();
23012 break;
23013 case warpEffectWave:
23014
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(out) wavyout(false);
23015 12 else wavyin();
23016 24 break;
23017 case warpEffectInstant:
23018 if(out) blackscr(30,true);
23019 break;
23020 case warpEffectMozaic:
23021 //!TODO Unimplemented
23022 break;
23023 case warpEffectOpen:
23024
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if(out) closescreen();
23025 4 else openscreen();
23026 8 break;
23027 }
23028 188 }
23029
23030 12 void FFScript::queueWarp(int32_t wtype, int32_t tdm, int32_t tscr, int32_t wx, int32_t wy,
23031 int32_t weff, int32_t wsfx, int32_t wflag, int32_t wdir)
23032 {
23033 12 warpex[wexActive] = 1;
23034 12 warpex[wexType] = wtype;
23035 12 warpex[wexDMap] = tdm;
23036 12 warpex[wexScreen] = tscr;
23037 12 warpex[wexX] = wx;
23038 12 warpex[wexY] = wy;
23039 12 warpex[wexEffect] = weff;
23040 12 warpex[wexSound] = wsfx;
23041 12 warpex[wexFlags] = wflag;
23042 12 warpex[wexDir] = wdir;
23043 12 }
23044
23045 104 bool FFScript::warp_player(int32_t warpType, int32_t dmap, int32_t screen, int32_t warpDestX, int32_t warpDestY, int32_t warpEffect, int32_t warpSound, int32_t warpFlags, int32_t heroFacesDir)
23046 {
23047 if(DEVLOGGING)
23048 {
23049 zprint("FFScript::warp_player() arg %s is: %d \n", "warpType", warpType);
23050 zprint("FFScript::warp_player() arg %s is: %d \n", "dmap", dmap);
23051 zprint("FFScript::warp_player() arg %s is: %d \n", "screen", screen);
23052 zprint("FFScript::warp_player() arg %s is: %d \n", "warpDestX", warpDestX);
23053 zprint("FFScript::warp_player() arg %s is: %d \n", "warpDestY", warpDestY);
23054 zprint("FFScript::warp_player() arg %s is: %d \n", "warpEffect", warpEffect);
23055 zprint("FFScript::warp_player() arg %s is: %d \n", "warpSound", warpSound);
23056 zprint("FFScript::warp_player() arg %s is: %d \n", "warpFlags", warpFlags);
23057 zprint("FFScript::warp_player() arg %s is: %d \n", "heroFacesDir", heroFacesDir);
23058 }
23059
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
104 if ( ((unsigned)dmap) >= MAXDMAPS )
23060 {
23061 Z_scripterrlog("Invalid DMap ID (%d) passed to WarpEx(). Aborting.\n", dmap);
23062 return false;
23063 }
23064
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
104 if ( ((unsigned)screen) >= MAPSCRS )
23065 {
23066 Z_scripterrlog("Invalid Screen Index (%d) passed to WarpEx(). Aborting.\n", screen);
23067 return false;
23068 }
23069 //Extra sanity guard.
23070
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
104 if ( map_screen_index(DMaps[dmap].map, screen + DMaps[dmap].xoff) >= (int32_t)TheMaps.size() )
23071 {
23072 Z_scripterrlog("Invalid destination passed to WarpEx(). Aborting.\n");
23073 return false;
23074 }
23075 104 byte t = 0;
23076 104 t=(cur_screen<128)?0:1;
23077 104 bool overlay=false;
23078 104 bool intradmap = (dmap == cur_dmap);
23079 104 int32_t olddmap = cur_dmap;
23080 //if ( intradmap )
23081 //{
23082 // initZScriptDMapScripts(); //Not needed.
23083 //}
23084
23085
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
104 if ( warpType == wtNOWARP ) { Z_eventlog("Used a Cancel Warped to DMap %d: %s, screen %d", cur_dmap, DMaps[cur_dmap].name,cur_screen); return false; }
23086 104 int32_t dest_map = DMaps[dmap].map;
23087 104 int32_t mapID = dest_map + 1;
23088 104 int32_t dest_dmap_xoff = DMaps[dmap].xoff;
23089 104 int32_t dest_screen = dest_dmap_xoff + screen;
23090 //mapscr *m = &TheMaps[mapID * MAPSCRS + scrID];
23091
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 mapscr *m = &TheMaps[(zc_max((mapID)-1,0) * MAPSCRS + dest_screen)];
23092
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 if ( warpFlags&warpFlagNOSTEPFORWARD ) FFCore.temp_no_stepforward = 1;
23093 104 int32_t wx = 0, wy = 0;
23094
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 85 times.
104 if ( warpDestX < 0 )
23095 {
23096 if(DEVLOGGING) zprint("WarpEx() was set to warp return point:%d\n", warpDestY);
23097
2/2
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 10 times.
85 if ( (unsigned)warpDestY < 4 )
23098 {
23099 75 wx = m->warpreturnx[warpDestY];
23100 75 wy = m->warpreturny[warpDestY];
23101 if(DEVLOGGING)
23102 {
23103 zprint("WarpEx Return Point X is: %d\n",wx);
23104 zprint("WarpEx Return Point Y is: %d\n",wy);
23105 }
23106 75 }
23107 else
23108 {
23109
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
10 if ( warpDestY == 5 || warpDestY < 0)
23110 {
23111 //Pit warp
23112 10 wx = Hero.getX();
23113 10 wy = Hero.getY();
23114 10 }
23115 else
23116 {
23117 Z_scripterrlog("Invalid Warp Return Square Type (%d) provided as an arg to Hero->WarpEx().\n",warpDestY);
23118 return false;
23119 }
23120 }
23121 85 }
23122 else
23123 {
23124 region_t region;
23125 int rx, ry;
23126 19 calculate_region(dest_map, dest_screen, region, rx, ry);
23127
2/4
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19 times.
19 if ( (unsigned)warpDestX < region.width && (unsigned)warpDestY < region.height )
23128 {
23129 19 wx = warpDestX;
23130 19 wy = warpDestY;
23131 19 }
23132 else
23133 {
23134 Z_scripterrlog("Invalid pixel coordinates of x = %d, y = %d, supplied to Hero->WarpEx()\n",warpDestX,warpDestY);
23135 return false;
23136 }
23137 }
23138 //warp coordinates are wx, wy, not x, y! -Z
23139
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 50 times.
104 if ( !(warpFlags&warpFlagDONTKILLSCRIPTDRAWS) ) script_drawing_commands.Clear();
23140 //we also need to check if dmaps are sideview here! -Z
23141 //Likewise, we need to add that check to the normal Hero:;dowarp(0
23142 104 bool wasSideview = isSideViewGravity(t);
23143
23144 //int32_t last_entr_scr = -1;
23145 //int32_t last_entr_dmap = -1;
23146
23147
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 if ( warpType < wtEXIT ) warpType = wtIWARP; //Sanity check. We can't use wtCave, or wtPassage, with scritped warps at present.
23148 104 Hero.is_warping = true;
23149
2/5
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
104 switch(warpType)
23150 {
23151 case wtIWARP:
23152 case wtIWARPBLK:
23153 case wtIWARPOPEN:
23154 case wtIWARPZAP:
23155 case wtIWARPWAVE:
23156 {
23157 94 bool wasswimming = (Hero.getAction()==swimming);
23158 94 bool wassideswim = (Hero.getAction()==sideswimming);
23159 94 int32_t olddiveclk = Hero.diveclk;
23160
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 94 times.
94 if ( !(warpFlags&warpFlagDONTCLEARSPRITES) )
23161 {
23162 94 ALLOFF();
23163 94 }
23164 else FFCore.AlloffLimited(warpFlags);
23165
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 78 times.
94 if (warpFlags&warpFlagFORCERESETMUSIC) music_stop();
23166
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 40 times.
94 if ( !(warpFlags&warpFlagDONTKILLSOUNDS) ) kill_sfx();
23167 94 sfx(warpSound);
23168
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 if(wasswimming)
23169 {
23170 Hero.setAction(swimming); FFCore.setHeroAction(swimming);
23171 Hero.diveclk = olddiveclk;
23172 }
23173
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 if(wassideswim)
23174 {
23175 Hero.setAction(sideswimming); FFCore.setHeroAction(sideswimming);
23176 Hero.diveclk = 0;
23177 }
23178 94 doWarpEffect(warpEffect, true);
23179 94 int32_t c = DMaps[cur_dmap].color;
23180 94 bool changedlevel = false;
23181 94 bool changeddmap = false;
23182
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 70 times.
94 if(cur_dmap != dmap)
23183 {
23184 70 timeExitAllGenscript(GENSCR_ST_CHANGE_DMAP);
23185 70 changeddmap = true;
23186 70 }
23187
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 52 times.
94 if(dlevel != DMaps[dmap].level)
23188 {
23189 52 timeExitAllGenscript(GENSCR_ST_CHANGE_LEVEL);
23190 52 changedlevel = true;
23191 52 }
23192 94 dlevel = DMaps[dmap].level;
23193 94 cur_dmap = dmap;
23194
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 70 times.
94 if(changeddmap)
23195 {
23196 70 throwGenScriptEvent(GENSCR_EVENT_CHANGE_DMAP);
23197 70 }
23198
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 52 times.
94 if(changedlevel)
23199 {
23200 52 throwGenScriptEvent(GENSCR_EVENT_CHANGE_LEVEL);
23201 52 }
23202 94 cur_map = DMaps[cur_dmap].map;
23203 94 init_dmap();
23204 94 update_subscreens(dmap);
23205
23206 94 ringcolor(false);
23207
23208
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 70 times.
94 if(DMaps[cur_dmap].color != c)
23209 70 loadlvlpal(DMaps[cur_dmap].color);
23210
23211 94 lightingInstant(); // Also sets naturaldark
23212 94 int prev_screen = hero_screen;
23213 94 loadscr(cur_dmap, screen + DMaps[cur_dmap].xoff, -1, overlay);
23214
23215 // In the case where we did not call ALLOFF, preserve the "enemies have spawned"
23216 // state for the new screen.
23217
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 if (warpFlags&warpFlagDONTCLEARSPRITES)
23218 {
23219 if (get_screen_state(prev_screen).loaded_enemies)
23220 get_screen_state(hero_screen).loaded_enemies = true;
23221 }
23222
23223 94 Hero.x = (zfix)wx;
23224 94 Hero.y = (zfix)wy;
23225 94 update_viewport();
23226
23227
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 28 times.
94 switch(heroFacesDir)
23228 {
23229 case up:
23230 case down:
23231 case left:
23232 case right:
23233 66 Hero.dir = heroFacesDir;
23234 66 break;
23235 default:
23236
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if((int32_t)Hero.x==(zfix)0)
23237 {
23238 Hero.dir=right;
23239 }
23240
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if((int32_t)Hero.x==(zfix)240)
23241 {
23242 Hero.dir=left;
23243 }
23244
23245
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if((int32_t)Hero.y==(zfix)0)
23246 {
23247 Hero.dir=down;
23248 }
23249
23250
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if((int32_t)Hero.y==(zfix)160)
23251 {
23252 Hero.dir=up;
23253 }
23254 28 }
23255
23256 94 markBmap(Hero.dir^1, hero_screen);
23257
23258
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 94 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 94 times.
94 if(iswaterex_z3(MAPCOMBO((int32_t)Hero.x,(int32_t)Hero.y+8), -1, Hero.x, Hero.y+8, true) && _walkflag((int32_t)Hero.x,(int32_t)Hero.y+8,0) && current_item(itype_flippers))
23259 {
23260 Hero.hopclk=0xFF;
23261 Hero.attackclk = Hero.charging = Hero.spins = 0;
23262 if (isSideViewHero() && get_qr(qr_SIDESWIM)) {Hero.setAction(sideswimming); FFCore.setHeroAction(sideswimming);}
23263 else {Hero.setAction(swimming); FFCore.setHeroAction(swimming);}
23264 }
23265 else
23266 {
23267 94 Hero.setAction(none); FFCore.setHeroAction(none);
23268 }
23269
23270 //preloaded freeform combos
23271 94 ffscript_engine(true);
23272
23273 94 putscr(hero_scr, scrollbuf, 0, 0);
23274 94 putscrdoors(hero_scr, scrollbuf, 0, 0);
23275
23276 94 doWarpEffect(warpEffect, false);
23277 94 show_subscreen_life=true;
23278 94 show_subscreen_numbers=true;
23279
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 90 times.
94 if (!(warpFlags&warpFlagFORCECONTINUEMUSIC)) Play_Level_Music();
23280 94 currcset=DMaps[cur_dmap].color;
23281 94 dointro();
23282 94 Hero.set_respawn_point();
23283 94 Hero.trySideviewLadder();
23284
23285 94 break;
23286 }
23287
23288
23289 case wtEXIT:
23290 {
23291 lighting(false,false,pal_litRESETONLY);//Reset permLit, and do nothing else; lighting was not otherwise called on a wtEXIT warp.
23292 ALLOFF();
23293 if (warpFlags&warpFlagFORCERESETMUSIC) music_stop();
23294 if ( !(warpFlags&warpFlagDONTKILLSOUNDS) ) kill_sfx();
23295 sfx(warpSound);
23296 blackscr(30,false);
23297 bool changedlevel = false;
23298 bool changeddmap = false;
23299 if(cur_dmap != dmap)
23300 {
23301 timeExitAllGenscript(GENSCR_ST_CHANGE_DMAP);
23302 changeddmap = true;
23303 }
23304 if(dlevel != DMaps[dmap].level)
23305 {
23306 timeExitAllGenscript(GENSCR_ST_CHANGE_LEVEL);
23307 changedlevel = true;
23308 }
23309 dlevel = DMaps[dmap].level;
23310 cur_dmap = dmap;
23311 if(changeddmap)
23312 {
23313 throwGenScriptEvent(GENSCR_EVENT_CHANGE_DMAP);
23314 }
23315 if(changedlevel)
23316 {
23317 throwGenScriptEvent(GENSCR_EVENT_CHANGE_LEVEL);
23318 }
23319 cur_map=DMaps[cur_dmap].map;
23320 init_dmap();
23321 update_subscreens(dmap);
23322 loadfullpal();
23323 ringcolor(false);
23324 loadlvlpal(DMaps[cur_dmap].color);
23325 loadscr(cur_dmap, screen + DMaps[cur_dmap].xoff, -1, overlay);
23326
23327 if((hero_scr->flags&fDARK) && !get_qr(qr_NEW_DARKROOM))
23328 {
23329 if(get_qr(qr_FADE))
23330 {
23331 interpolatedfade();
23332 }
23333 else
23334 {
23335 loadfadepal((DMaps[cur_dmap].color)*pdLEVEL+poFADE3);
23336 }
23337
23338 darkroom=naturaldark=true;
23339 }
23340 else
23341 {
23342 darkroom=naturaldark=false;
23343 }
23344
23345
23346 //Move Hero's coordinates
23347 Hero.x = (zfix)wx;
23348 Hero.y = (zfix)wy;
23349 update_viewport();
23350
23351 //set his dir
23352 switch(heroFacesDir)
23353 {
23354 case up:
23355 case down:
23356 case left:
23357 case right:
23358 Hero.dir = heroFacesDir;
23359 break;
23360 default:
23361 Hero.dir=down;
23362 if((int32_t)Hero.x==(zfix)0)
23363 {
23364 Hero.dir=right;
23365 }
23366 if((int32_t)Hero.x==(zfix)240)
23367 {
23368 Hero.dir=left;
23369 }
23370
23371 if((int32_t)Hero.y==(zfix)0)
23372 {
23373 Hero.dir=down;
23374 }
23375
23376 if((int32_t)Hero.y==(zfix)160)
23377 {
23378 Hero.dir=up;
23379 }
23380 }
23381
23382 if(dlevel)
23383 {
23384 // reset enemy kill counts
23385 for(int32_t i=0; i<128; i++)
23386 {
23387 int mi = mapind(cur_map, i);
23388 game->guys[mi] = 0;
23389 game->maps[mi] &= ~mTMPNORET;
23390 }
23391 }
23392
23393 markBmap(Hero.dir^1, hero_screen);
23394 //preloaded freeform combos
23395 ffscript_engine(true);
23396 Hero.reset_hookshot();
23397
23398 if(isdungeon())
23399 {
23400 openscreen();
23401 if(get_er(er_SHORTDGNWALK)==0 && get_qr(qr_SHORTDGNWALK)==0)
23402 Hero.stepforward(Hero.diagonalMovement?11:12, false);
23403 else
23404 // Didn't walk as far pre-1.93, and some quests depend on that
23405 Hero.stepforward(8, false);
23406 }
23407 else
23408 {
23409 openscreen();
23410 }
23411
23412 show_subscreen_life=true;
23413 show_subscreen_numbers=true;
23414 if (!(warpFlags&warpFlagFORCECONTINUEMUSIC))Play_Level_Music();
23415 currcset=DMaps[cur_dmap].color;
23416 dointro();
23417 Hero.set_respawn_point();
23418 Hero.trySideviewLadder();
23419
23420 for(int32_t i=0; i<6; i++)
23421 visited[i]=-1;
23422
23423 //last_entr_scr = scrID;
23424 //last_entr_dmap = dmapID;
23425
23426 break;
23427
23428 }
23429 case wtSCROLL: // scrolling warp
23430 {
23431 10 int32_t c = DMaps[cur_dmap].color;
23432 10 scrolling_dmap = cur_dmap;
23433 10 scrolling_map = cur_map;
23434 10 cur_map = DMaps[dmap].map;
23435 10 update_subscreens(dmap);
23436
23437 10 dlevel = DMaps[dmap].level;
23438 //check if Hero has the map for the new location before updating the subscreen. ? -Z
23439 //This works only in one direction, if Hero had a map, to not having one.
23440 //If Hero does not have a map, and warps somewhere where he does, then the map still briefly shows.
23441 10 update_subscreens(dmap);
23442
23443 // if ( has_item(itype_map, dlevel) )
23444 // {
23445 // //Blank the map during an intra-dmap scrolling warp.
23446 // dlevel = -1; //a hack for the minimap. This works!! -Z
23447 // }
23448
23449 // fix the scrolling direction, if it was a tile or instant warp
23450 10 Hero.sdir = vbound(Hero.dir,0,3);
23451
23452
23453 10 Hero.scrollscr(Hero.sdir, screen+DMaps[dmap].xoff, dmap);
23454 10 bool changedlevel = false;
23455 10 bool changeddmap = false;
23456
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(cur_dmap != dmap)
23457 {
23458 timeExitAllGenscript(GENSCR_ST_CHANGE_DMAP);
23459 changeddmap = true;
23460 }
23461
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(dlevel != DMaps[dmap].level)
23462 {
23463 timeExitAllGenscript(GENSCR_ST_CHANGE_LEVEL);
23464 changedlevel = true;
23465 }
23466 10 dlevel = DMaps[dmap].level;
23467 10 cur_dmap = dmap;
23468
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(changeddmap)
23469 {
23470 throwGenScriptEvent(GENSCR_EVENT_CHANGE_DMAP);
23471 }
23472
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(changedlevel)
23473 {
23474 throwGenScriptEvent(GENSCR_EVENT_CHANGE_LEVEL);
23475 }
23476
23477 10 Hero.reset_hookshot();
23478
23479
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(!intradmap)
23480 {
23481
5/8
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 10 times.
10 if(((wx>0||wy>0)||(get_qr(qr_WARPSIGNOREARRIVALPOINT)))&&(!get_qr(qr_NOSCROLLCONTINUE))&&(!(hero_scr->flags6&fNOCONTINUEHERE)))
23482 {
23483
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 6 times.
10 if(dlevel)
23484 {
23485 6 lastentrance = cur_screen;
23486 6 }
23487 else
23488 {
23489 4 lastentrance = DMaps[cur_dmap].cont + DMaps[cur_dmap].xoff;
23490 }
23491
23492 10 lastentrance_dmap = dmap;
23493 10 }
23494 10 }
23495
23496
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(DMaps[cur_dmap].color != c)
23497 {
23498 lighting(false, true);
23499 }
23500
23501
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (!(warpFlags&warpFlagFORCECONTINUEMUSIC)) Play_Level_Music();
23502 10 currcset=DMaps[cur_dmap].color;
23503 10 dointro();
23504 10 break;
23505 }
23506 //Cannot use these types with scripts, or with strings.
23507 case wtCAVE:
23508 case wtPASS:
23509 case wtWHISTLE:
23510 default:
23511 {
23512 Z_scripterrlog("Invalid warp type (%d) supplied to Hero->WarpEx()!. Cannot warp!!\n", warpType);
23513 Hero.is_warping = false;
23514 return false;
23515 }
23516 }
23517 // Stop Hero from drowning!
23518
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 if(Hero.getAction()==drowning)
23519 {
23520 Hero.drownclk=0;
23521 Hero.setAction(none); FFCore.setHeroAction(none);
23522 }
23523
23524 // But keep him swimming if he ought to be!
23525
3/8
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 104 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 104 times.
✗ Branch 7 not taken.
104 if(Hero.getAction()!=rafting && iswaterex_z3(MAPCOMBO((int32_t)Hero.x,(int32_t)Hero.y+8), -1, Hero.x, Hero.y+8, true) && (_walkflag((int32_t)Hero.x,(int32_t)Hero.y+8,0) || get_qr(qr_DROWN))
23526 && (current_item(itype_flippers)) && (Hero.getAction()!=inwind))
23527 {
23528 Hero.hopclk=0xFF;
23529 if (isSideViewHero() && get_qr(qr_SIDESWIM)) {Hero.setAction(sideswimming); FFCore.setHeroAction(sideswimming);}
23530 else {Hero.setAction(swimming); FFCore.setHeroAction(swimming);}
23531 }
23532
23533 104 newscr_clk=frame;
23534 104 activated_timed_warp=false;
23535 104 eat_buttons();
23536
23537
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 26 times.
104 if(warpType!=wtIWARP) { Hero.attackclk=0; }
23538
23539 104 Hero.didstuff=0;
23540 104 Hero.usecounts.clear();
23541 104 map_bkgsfx(true);
23542 104 loadside=Hero.dir^1;
23543 104 whistleclk=-1;
23544
23545
2/4
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 104 times.
✗ Branch 3 not taken.
104 if(((int32_t)Hero.z>0 || (int32_t)Hero.fakez>0) && isSideViewHero())
23546 {
23547 Hero.y-=Hero.z;
23548 Hero.y-=Hero.fakez;
23549 Hero.z=0;
23550 Hero.fakez=0;
23551 }
23552
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
104 else if(!isSideViewHero())
23553 {
23554 104 Hero.fall=0;
23555 104 Hero.fakefall=0;
23556 104 }
23557
23558 // If warping between top-down and sideview screens,
23559 // fix enemies that are carried over by Full Screen Warp
23560 104 const bool tmpscr_is_sideview = isSideViewGravity();
23561
23562
2/4
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 104 times.
✗ Branch 3 not taken.
104 if(!wasSideview && tmpscr_is_sideview)
23563 {
23564 for(int32_t i=0; i<guys.Count(); i++)
23565 {
23566 if(guys.spr(i)->z > 0)
23567 {
23568 guys.spr(i)->y -= guys.spr(i)->z;
23569 guys.spr(i)->z = 0;
23570 }
23571
23572 if(((enemy*)guys.spr(i))->family!=eeTRAP && ((enemy*)guys.spr(i))->family!=eeSPINTILE)
23573 guys.spr(i)->yofs += 2;
23574 }
23575 }
23576
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
104 else if(wasSideview && !tmpscr_is_sideview)
23577 {
23578 for(int32_t i=0; i<guys.Count(); i++)
23579 {
23580 if(((enemy*)guys.spr(i))->family!=eeTRAP && ((enemy*)guys.spr(i))->family!=eeSPINTILE)
23581 guys.spr(i)->yofs -= 2;
23582 }
23583 }
23584
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
104 if ( warpType == wtEXIT )
23585 {
23586 game->set_continue_scrn(cur_screen);
23587 game->set_continue_dmap(dmap);
23588 lastentrance = cur_screen;
23589 lastentrance_dmap = dmap;
23590 }
23591 else
23592 {
23593
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 4 times.
104 if ( (warpFlags&warpFlagSETENTRANCESCREEN) ) lastentrance = cur_screen;
23594
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 4 times.
104 if ( (warpFlags&warpFlagSETENTRANCEDMAP) ) lastentrance_dmap = dmap;
23595
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 4 times.
104 if ( (warpFlags&warpFlagSETCONTINUESCREEN) ) game->set_continue_scrn(cur_screen);
23596
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 4 times.
104 if ( (warpFlags&warpFlagSETCONTINUEDMAP) ) game->set_continue_dmap(dmap);
23597 }
23598
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 if(hero_scr->flags4&fAUTOSAVE)
23599 {
23600 save_game(true,0);
23601 }
23602
23603
2/2
✓ Branch 0 taken 103 times.
✓ Branch 1 taken 1 times.
104 if(hero_scr->flags6&fCONTINUEHERE)
23604 {
23605 1 lastentrance_dmap = cur_dmap;
23606 1 lastentrance = home_screen;
23607 1 }
23608
23609 104 update_subscreens();
23610 104 verifyBothWeapons();
23611 208 Z_eventlog("Warped to DMap %d: %s, screen %d, via %s.\n", cur_dmap, DMaps[cur_dmap].name,cur_screen,
23612
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
208 warpType==wtEXIT ? "Entrance/Exit" :
23613
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 94 times.
104 warpType==wtSCROLL ? "Scrolling Warp" :
23614 94 warpType==wtNOWARP ? "Cancel Warp" :
23615 "Insta-Warp");
23616
23617 104 eventlog_mapflags();
23618
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 104 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
104 if (((warpFlags&warpFlagDONTRESTARTDMAPSCRIPT) != 0) == (get_qr(qr_SCRIPT_WARPS_DMAP_SCRIPT_TOGGLE) != 0)|| olddmap != cur_dmap) //Changed DMaps, or needs to reset the script
23619 {
23620 104 FFScript::deallocateAllScriptOwned(ScriptType::DMap, olddmap);
23621 104 initZScriptDMapScripts();
23622 104 }
23623 104 Hero.is_warping = false;
23624
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 88 times.
104 if(!get_qr(qr_SCROLLWARP_NO_RESET_FRAME))
23625 88 GameFlags |= GAMEFLAG_RESET_GAME_LOOP;
23626 104 return true;
23627 104 }
23628
23629 2004 void FFScript::do_adjustvolume(const bool v)
23630 {
23631
1/2
✓ Branch 0 taken 2004 times.
✗ Branch 1 not taken.
2004 if (get_qr(qr_OLD_SCRIPT_VOLUME))
23632 {
23633 2004 int32_t perc = (SH::get_arg(sarg1, v) / 10000);
23634 2004 float pct = perc / 100.0;
23635 2004 float temp_midi = 0;
23636 2004 float temp_digi = 0;
23637 2004 float temp_mus = 0;
23638
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 4 times.
2004 if (!(coreflags & FFCORE_SCRIPTED_MIDI_VOLUME))
23639 {
23640 4 temp_midi = do_getMIDI_volume();
23641 4 usr_midi_volume = do_getMIDI_volume();
23642 4 SetFFEngineFlag(FFCORE_SCRIPTED_MIDI_VOLUME, true);
23643 4 }
23644 else
23645 {
23646 2000 temp_midi = (float)usr_midi_volume;
23647 }
23648
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 4 times.
2004 if (!(coreflags & FFCORE_SCRIPTED_DIGI_VOLUME))
23649 {
23650 4 temp_digi = do_getDIGI_volume();
23651 4 usr_digi_volume = do_getDIGI_volume();
23652 4 SetFFEngineFlag(FFCORE_SCRIPTED_DIGI_VOLUME, true);
23653 4 }
23654 else
23655 {
23656 2000 temp_digi = (float)usr_digi_volume;
23657 }
23658
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 4 times.
2004 if (!(coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME))
23659 {
23660 4 temp_mus = do_getMusic_volume();
23661 4 usr_music_volume = do_getMusic_volume();
23662 4 SetFFEngineFlag(FFCORE_SCRIPTED_MUSIC_VOLUME, true);
23663 4 }
23664 else
23665 {
23666 2000 temp_mus = (float)usr_music_volume;
23667 }
23668
23669 2004 temp_midi *= pct;
23670 2004 temp_digi *= pct;
23671 2004 temp_mus *= pct;
23672 2004 do_setMIDI_volume((int32_t)temp_midi);
23673 2004 do_setDIGI_volume((int32_t)temp_digi);
23674 2004 do_setMusic_volume((int32_t)temp_mus);
23675 2004 }
23676 else
23677 {
23678 int32_t perc = SH::get_arg(sarg1, v);
23679 FFCore.usr_music_volume = vbound(perc, 0, 10000 * 100);
23680
23681 if (zcmusic != NULL)
23682 {
23683 if (zcmusic->playing != ZCM_STOPPED)
23684 {
23685 int32_t temp_volume = emusic_volume;
23686 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
23687 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
23688 temp_volume = (temp_volume * zcmusic->fadevolume) / 10000;
23689 zcmusic_play(zcmusic, temp_volume);
23690 return;
23691 }
23692 }
23693 else if (currmidi > -1)
23694 {
23695 jukebox(currmidi);
23696 master_volume(digi_volume, midi_volume);
23697 }
23698 }
23699 2004 }
23700
23701 void FFScript::do_adjustsfxvolume(const bool v)
23702 {
23703 if (get_qr(qr_OLD_SCRIPT_VOLUME))
23704 {
23705 int32_t perc = (SH::get_arg(sarg1, v) / 10000);
23706 float pct = perc / 100.0;
23707 float temp_sfx = 0;
23708 if (!(coreflags & FFCORE_SCRIPTED_SFX_VOLUME))
23709 {
23710 temp_sfx = do_getSFX_volume();
23711 usr_sfx_volume = (int32_t)temp_sfx;
23712 SetFFEngineFlag(FFCORE_SCRIPTED_SFX_VOLUME, true);
23713 }
23714 else
23715 {
23716 temp_sfx = (float)usr_sfx_volume;
23717 }
23718 temp_sfx *= pct;
23719 do_setSFX_volume((int32_t)temp_sfx);
23720 }
23721 else
23722 {
23723 int32_t perc = SH::get_arg(sarg1, v);
23724 FFCore.usr_sfx_volume = vbound(perc, 0, 10000 * 100);
23725 }
23726 }
23727
23728
23729 63829 void do_midi(bool v)
23730 {
23731 63829 int32_t MIDI = SH::get_arg(sarg1, v) / 10000;
23732
23733
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 63786 times.
63829 if(MIDI == 0)
23734 43 music_stop();
23735 else
23736 63786 jukebox(MIDI + (ZC_MIDI_COUNT - 1));
23737 63829 }
23738
23739
23740 1 void stop_sfx(const bool v)
23741 {
23742 1 int32_t ID = SH::get_arg(sarg1, v) / 10000;
23743 1 int32_t sfx = (int32_t)ID;
23744
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(BC::checkSFXID(ID) != SH::_NoError)
23745 return;
23746 1 stop_sfx(sfx);
23747 1 }
23748
23749 void pause_sfx(const bool v)
23750 {
23751 int32_t ID = SH::get_arg(sarg1, v) / 10000;
23752 int32_t sfx = (int32_t)ID;
23753 if(BC::checkSFXID(ID) != SH::_NoError)
23754 return;
23755 pause_sfx(sfx);
23756 }
23757
23758 void resume_sfx(const bool v)
23759 {
23760 int32_t ID = SH::get_arg(sarg1, v) / 10000;
23761 int32_t sfx = (int32_t)ID;
23762 if(BC::checkSFXID(ID) != SH::_NoError)
23763 return;
23764 resume_sfx(sfx);
23765 }
23766
23767
23768
23769 178 void do_enh_music(bool v)
23770 {
23771 178 int32_t arrayptr = SH::get_arg(sarg1, v);
23772 178 int32_t track = (SH::get_arg(sarg2, v) / 10000)-1;
23773
23774
1/2
✓ Branch 0 taken 178 times.
✗ Branch 1 not taken.
178 if(arrayptr == 0)
23775 music_stop();
23776 else // Pointer to a string..
23777 {
23778 178 string filename_str;
23779 char filename_char[256];
23780 bool ret;
23781
1/2
✓ Branch 0 taken 178 times.
✗ Branch 1 not taken.
178 ArrayH::getString(arrayptr, filename_str, 256);
23782 178 strncpy(filename_char, filename_str.c_str(), 255);
23783 178 filename_char[255]='\0';
23784
2/4
✓ Branch 0 taken 178 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 178 times.
✗ Branch 3 not taken.
178 ret=try_zcmusic(filename_char, qstpath, track, -1000, get_emusic_volume());
23785
1/2
✓ Branch 0 taken 178 times.
✗ Branch 1 not taken.
178 set_register(sarg2, ret ? 10000 : 0);
23786 178 }
23787 178 }
23788
23789 5 void do_enh_music_crossfade()
23790 {
23791 5 int32_t arrayptr = SH::read_stack(ri->sp + 5);
23792 5 int32_t track = SH::read_stack(ri->sp + 4) / 10000;
23793
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 int32_t fadeoutframes = zc_max(SH::read_stack(ri->sp + 3) / 10000, 0);
23794
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 int32_t fadeinframes = zc_max(SH::read_stack(ri->sp + 2) / 10000, 0);
23795 5 int32_t fademiddleframes = SH::read_stack(ri->sp + 1) / 10000;
23796 5 int32_t startpos = SH::read_stack(ri->sp);
23797
23798
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (arrayptr == 0)
23799 {
23800 bool ret = play_enh_music_crossfade(NULL, qstpath, track, get_emusic_volume(), fadeoutframes, fadeinframes, fademiddleframes, startpos);
23801 ri->d[rEXP1] = ret ? 10000 : 0;
23802 }
23803 else
23804 {
23805 5 string filename_str;
23806 char filename_char[256];
23807
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 ArrayH::getString(arrayptr, filename_str, 256);
23808 5 strncpy(filename_char, filename_str.c_str(), 255);
23809 5 filename_char[255] = '\0';
23810
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 bool ret = play_enh_music_crossfade(filename_char, qstpath, track, get_emusic_volume(), fadeoutframes, fadeinframes, fademiddleframes, startpos, true);
23811 5 ri->d[rEXP1] = ret ? 10000 : 0;
23812 5 }
23813 5 }
23814
23815 bool FFScript::doing_dmap_enh_music(int32_t dm)
23816 {
23817 if (DMaps[dm].tmusic[0] != 0)
23818 {
23819 if (zcmusic != NULL)
23820 {
23821 if (strcmp(zcmusic->filename, DMaps[dm].tmusic) == 0)
23822 {
23823 switch (zcmusic_get_type(zcmusic))
23824 {
23825 case ZCMF_OGG:
23826 case ZCMF_MP3:
23827 return true;
23828 case ZCMF_DUH:
23829 case ZCMF_GME:
23830 if (zcmusic->track == DMaps[dm].tmusictrack)
23831 {
23832 return true;
23833 }
23834 }
23835 }
23836 }
23837 }
23838 return false;
23839 }
23840
23841 37945 bool FFScript::can_dmap_change_music(int32_t dm)
23842 {
23843
1/4
✓ Branch 0 taken 37945 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
37945 switch (music_update_cond)
23844 {
23845 case MUSIC_UPDATE_SCREEN:
23846 37945 return true;
23847 case MUSIC_UPDATE_DMAP:
23848 return dm != -1 && dm != cur_dmap;
23849 case MUSIC_UPDATE_LEVEL:
23850 return dm != -1 && DMaps[dm].level != DMaps[cur_dmap].level;
23851 }
23852 return false;
23853 37945 }
23854
23855 void FFScript::do_set_music_position(const bool v)
23856 {
23857 int32_t newposition = SH::get_arg(sarg1, v);
23858
23859 set_zcmusicpos(newposition);
23860 }
23861
23862 void FFScript::do_get_music_position()
23863 {
23864 int32_t pos = replay_get_state(ReplayStateType::MusicPosition, [](){
23865 return zcmusic_get_curpos(zcmusic);
23866 });
23867 set_register(sarg1, pos);
23868 }
23869
23870 void FFScript::do_set_music_speed(const bool v)
23871 {
23872 int32_t newspeed = SH::get_arg(sarg1, v);
23873 set_zcmusicspeed(newspeed);
23874 }
23875
23876 void FFScript::do_get_music_length()
23877 {
23878 int32_t len = get_zcmusiclen();
23879 set_register(sarg1, len);
23880 }
23881
23882 3 void FFScript::do_set_music_loop()
23883 {
23884 3 double start = (get_register(sarg1) / 10000.0);
23885 3 double end = (get_register(sarg2) / 10000.0);
23886
23887 3 set_zcmusicloop(start, end);
23888 3 }
23889
23890 236 void do_get_enh_music_filename(const bool v)
23891 {
23892 236 int32_t ID = SH::get_arg(sarg1, v) / 10000;
23893 236 int32_t arrayptr = get_register(sarg2);
23894
23895
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 236 times.
236 if(BC::checkDMapID(ID) != SH::_NoError)
23896 return;
23897
23898
3/6
✓ Branch 0 taken 236 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 236 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 236 times.
✗ Branch 5 not taken.
236 if(ArrayH::setArray(arrayptr, string(DMaps[ID].tmusic)) == SH::_Overflow)
23899 Z_scripterrlog("Array supplied to 'Game->GetDMapMusicFilename' not large enough\n");
23900 236 }
23901
23902 140 void do_get_enh_music_track(const bool v)
23903 {
23904 140 int32_t ID = SH::get_arg(sarg1, v) / 10000;
23905
23906
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 132 times.
140 if(BC::checkDMapID(ID) != SH::_NoError)
23907 8 return;
23908
23909 132 set_register(sarg1, (DMaps[ID].tmusictrack+1)*10000);
23910 140 }
23911
23912 3783 void do_set_dmap_enh_music(const bool v)
23913 {
23914 3783 int32_t ID = SH::read_stack(ri->sp + 2) / 10000;
23915 3783 int32_t arrayptr = SH::read_stack(ri->sp + 1);
23916 3783 int32_t track = (SH::read_stack(ri->sp + 0) / 10000)-1;
23917 3783 string filename_str;
23918
23919
2/4
✓ Branch 0 taken 3783 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3783 times.
✗ Branch 3 not taken.
3783 if(BC::checkDMapID(ID) != SH::_NoError)
23920 return;
23921
23922
1/2
✓ Branch 0 taken 3783 times.
✗ Branch 1 not taken.
3783 ArrayH::getString(arrayptr, filename_str, 56);
23923 3783 strncpy(DMaps[ID].tmusic, filename_str.c_str(), 55);
23924 3783 DMaps[ID].tmusic[55]='\0';
23925 3783 DMaps[ID].tmusictrack=track;
23926
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3783 times.
3783 }
23927
23928
23929
23930
23931
23932
23933 ///----------------------------------------------------------------------------------------------------//
23934 //Array & string related
23935
23936 303069076 void do_arraysize()
23937 {
23938 303069076 int32_t arrayptr = get_register(sarg1);
23939 303069076 ri->d[rEXP1] = ArrayH::getSize(arrayptr) * 10000;
23940 303069076 }
23941
23942 void do_tobyte()
23943 {
23944 int32_t b1 = get_register(sarg1) / 10000;
23945 byte b2 = b1;
23946 set_register(sarg1, b2 * 10000);
23947 }
23948
23949 void do_tosignedbyte()
23950 {
23951 int32_t b1 = get_register(sarg1) / 10000;
23952 signed char b2 = b1;
23953 set_register(sarg1, b2 * 10000);
23954 }
23955
23956 void do_tointeger()
23957 {
23958 int32_t b1 = get_register(sarg1) / 10000;
23959 set_register(sarg1, b1 * 10000);
23960 }
23961
23962 7 void do_floor()
23963 {
23964 7 set_register(sarg1, zslongToFix(get_register(sarg1)).doFloor().getZLong());
23965 7 }
23966
23967 void do_trunc()
23968 {
23969 set_register(sarg1, zslongToFix(get_register(sarg1)).doTrunc().getZLong());
23970 }
23971
23972 void do_ceiling()
23973 {
23974 set_register(sarg1, zslongToFix(get_register(sarg1)).doCeil().getZLong());
23975 }
23976
23977 void do_round()
23978 {
23979 set_register(sarg1, zslongToFix(get_register(sarg1)).doRound().getZLong());
23980 }
23981
23982 void do_roundaway()
23983 {
23984 set_register(sarg1, zslongToFix(get_register(sarg1)).doRoundAway().getZLong());
23985 }
23986
23987 void do_toword()
23988 {
23989 int32_t b1 = get_register(sarg1) / 10000;
23990 word b2 = b1;
23991 set_register(sarg1, b2 * 10000);
23992 }
23993
23994 void do_toshort()
23995 {
23996 int32_t b1 = get_register(sarg1) / 10000;
23997 int16_t b2 = b1;
23998 set_register(sarg1, b2 * 10000);
23999 }
24000
24001 //Set npc and item names t.b.a. -Z
24002
24003 2768 void do_getitemname()
24004 {
24005 2768 int32_t arrayptr = get_register(sarg1);
24006
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2768 times.
2768 if(unsigned(ri->idata) >= MAXITEMS)
24007 {
24008 scripting_log_error_with_context("Invalid itemdata access: {}", ri->idata);
24009 return;
24010 }
24011
24012
3/6
✓ Branch 0 taken 2768 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2768 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2768 times.
✗ Branch 5 not taken.
2768 if(ArrayH::setArray(arrayptr, item_string[ri->idata]) == SH::_Overflow)
24013 Z_scripterrlog("Array supplied to 'itemdata->GetName' not large enough\n");
24014 2768 }
24015
24016 10105619 void do_getffcscript()
24017 {
24018 10105619 do_get_script_index_by_name(name_to_slot_index_ffcmap);
24019 10105619 }
24020
24021 80 void do_getitemscript()
24022 {
24023 80 do_get_script_index_by_name(name_to_slot_index_itemmap);
24024 80 }
24025
24026 ///----------------------------------------------------------------------------------------------------//
24027 //Tile Manipulation
24028
24029 49233778 void do_copytile(const bool v, const bool v2)
24030 {
24031 49233778 int32_t tile = SH::get_arg(sarg1, v) / 10000;
24032 49233778 int32_t tile2 = SH::get_arg(sarg2, v2) / 10000;
24033
24034 49233778 copy_tile(newtilebuf, tile, tile2, false);
24035 49233778 }
24036
24037 int32_t FFScript::IsBlankTile(int32_t i)
24038 {
24039 if( ((unsigned)i) > NEWMAXTILES )
24040 {
24041 Z_scripterrlog("Invalid tile ID (%d) passed to Graphics->IsBlankTile[]\n");
24042 return -1;
24043 }
24044
24045 byte *tilestart=newtilebuf[i].data;
24046 qword *di=(qword*)tilestart;
24047 int32_t parts=tilesize(newtilebuf[i].format)>>3;
24048
24049 for(int32_t j=0; j<parts; ++j, ++di)
24050 {
24051 if(*di!=0)
24052 {
24053 return 0;
24054 }
24055 }
24056
24057 return 1;
24058 }
24059
24060 int32_t FFScript::Is8BitTile(int32_t i)
24061 {
24062 if (((unsigned)i) > NEWMAXTILES)
24063 {
24064 Z_scripterrlog("Invalid tile ID (%d) passed to Graphics->Is8BitTile[]\n");
24065 return -1;
24066 }
24067
24068 return newtilebuf[i].format == tf8Bit ? 1 : 0;
24069 }
24070
24071 void do_swaptile(const bool v, const bool v2)
24072 {
24073 int32_t tile = SH::get_arg(sarg1, v) / 10000;
24074 int32_t tile2 = SH::get_arg(sarg2, v2) / 10000;
24075
24076 copy_tile(newtilebuf, tile, tile2, true);
24077 }
24078
24079 57032 void do_overlaytile(const bool v, const bool v2)
24080 {
24081 57032 int32_t tile = SH::get_arg(sarg1, v) / 10000;
24082 57032 int32_t tile2 = SH::get_arg(sarg2, v2) / 10000;
24083
24084
2/4
✓ Branch 0 taken 57032 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57032 times.
✗ Branch 3 not taken.
57032 if(BC::checkTile(tile) != SH::_NoError ||
24085 57032 BC::checkTile(tile2) != SH::_NoError)
24086 return;
24087
24088 //Could add an arg for the CSet or something instead of just passing 0, currently only 8-bit is supported
24089 57032 overlay_tile(newtilebuf, tile, tile2, 0, false);
24090 57032 }
24091
24092 void do_fliprotatetile(const bool v, const bool v2)
24093 {
24094 int32_t tile = SH::get_arg(sarg1, v) / 10000;
24095 int32_t tile2 = SH::get_arg(sarg2, v2) / 10000;
24096
24097 if(BC::checkTile(tile) != SH::_NoError ||
24098 BC::checkTile(tile2) != SH::_NoError)
24099 return;
24100
24101 //fliprotatetile
24102 }
24103
24104 void do_settilepixel()
24105 {
24106 int32_t tile = SH::read_stack(ri->sp + 3) / 10000;
24107 int32_t x = SH::read_stack(ri->sp + 2) / 10000;
24108 int32_t y = SH::read_stack(ri->sp + 1) / 10000;
24109 int32_t val = SH::read_stack(ri->sp + 0) / 10000;
24110
24111 if(BC::checkTile(tile) != SH::_NoError)
24112 return;
24113
24114 x = vbound(x, 0, 15);
24115 y = vbound(y, 0, 15);
24116 unpack_tile(newtilebuf, tile, 0, false);
24117 if (newtilebuf[tile].format == tf4Bit)
24118 val &= 0xF;
24119 unpackbuf[y * 16 + x] = val;
24120 pack_tile(newtilebuf, unpackbuf, tile);
24121 }
24122
24123 void do_gettilepixel()
24124 {
24125 int32_t tile = SH::read_stack(ri->sp + 3) / 10000;
24126 int32_t x = SH::read_stack(ri->sp + 2) / 10000;
24127 int32_t y = SH::read_stack(ri->sp + 1) / 10000;
24128 int32_t cs = SH::read_stack(ri->sp + 0) / 10000;
24129
24130 if(BC::checkTile(tile) != SH::_NoError)
24131 return;
24132
24133 x = vbound(x, 0, 15);
24134 y = vbound(y, 0, 15);
24135 unpack_tile(newtilebuf, tile, 0, false);
24136 int32_t csoffs = newtilebuf[tile].format == tf8Bit ? 0 : cs * 16;
24137 ri->d[rEXP1] = 10000 * (unpackbuf[y * 16 + x] + csoffs);
24138 }
24139
24140 void do_shifttile(const bool v, const bool v2)
24141 {
24142 int32_t tile = SH::get_arg(sarg1, v) / 10000;
24143 int32_t tile2 = SH::get_arg(sarg2, v2) / 10000;
24144
24145 if(BC::checkTile(tile) != SH::_NoError ||
24146 BC::checkTile(tile2) != SH::_NoError)
24147 return;
24148
24149 //shifttile
24150 }
24151
24152 10 void do_cleartile(const bool v)
24153 {
24154 10 int32_t tile = SH::get_arg(sarg1, v) / 10000;
24155
24156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(BC::checkTile(tile) != SH::_NoError)
24157 return;
24158
24159 10 reset_tile(newtilebuf, tile, newtilebuf[tile].format);
24160 10 }
24161
24162 3062 void do_combotile(const bool v)
24163 {
24164 3062 int32_t combo = SH::get_arg(sarg2, v) / 10000;
24165
24166
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3062 times.
3062 if(BC::checkCombo(combo) != SH::_NoError)
24167 return;
24168
24169 3062 set_register(sarg1, combobuf[combo].tile * 10000);
24170 3062 }
24171
24172 232889793 void do_readpod(const bool v)
24173 {
24174 232889793 int32_t indx = SH::get_arg(sarg2, v) / 10000;
24175 232889793 int32_t val = ArrayH::getElement(ri->d[rINDEX], indx, can_neg_array);
24176 232889793 set_register(sarg1, val);
24177 232889793 }
24178 134158261 void do_writepod(const bool v1, const bool v2)
24179 {
24180 134158261 int32_t indx = SH::get_arg(sarg1, v1) / 10000;
24181 134158261 int32_t val = SH::get_arg(sarg2, v2);
24182 134158261 ArrayH::setElement(ri->d[rINDEX], indx, val, can_neg_array);
24183 134158261 }
24184 3240415 void do_writepodstr()
24185 {
24186
2/2
✓ Branch 0 taken 30329 times.
✓ Branch 1 taken 3210086 times.
3240415 if(!sargstr) return;
24187 3210086 uint32_t id = get_register(sarg1);
24188 3210086 ArrayH::setArray(id, *sargstr);
24189 3240415 }
24190 560049 void do_writepodarr()
24191 {
24192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 560049 times.
560049 if(!sargvec) return;
24193
24194 560049 uint32_t id = get_register(sarg1);
24195 560049 ArrayH::setArray(id, sargvec->size(), sargvec->data(), false);
24196 560049 }
24197
24198 25 int32_t get_own_i(ScriptType type)
24199 {
24200
1/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
25 switch(type)
24201 {
24202 case ScriptType::Lwpn:
24203 return ri->lwpn;
24204 case ScriptType::Ewpn:
24205 return ri->ewpn;
24206 case ScriptType::ItemSprite:
24207 return ri->itemref;
24208 case ScriptType::NPC:
24209 25 return ri->guyref;
24210 case ScriptType::FFC:
24211 if (auto ffc = ResolveFFC(ri->ffcref))
24212 return ffc->index;
24213 }
24214 return 0;
24215 25 }
24216
24217 portal* loadportal(savedportal& p);
24218
24219 ///----------------------------------------------------------------------------------------------------//
24220 // Run the script //
24221 ///----------------------------------------------------------------------------------------------------//
24222
24223 2947 static bool check_cmp(uint cmp)
24224 {
24225
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2947 times.
2947 if(cmp & CMP_BOOL)
24226 {
24227 if(ri->cmp_strcache) return false; //Cast string to bool? nonsense...
24228 switch(cmp & CMP_FLAGS)
24229 {
24230 case CMP_EQ:
24231 return !ri->cmp_op1 == !ri->cmp_op2;
24232 case CMP_NE:
24233 return !ri->cmp_op1 != !ri->cmp_op2;
24234 }
24235 return false;
24236 }
24237
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2947 times.
2947 else if(ri->cmp_strcache)
24238 {
24239 if(*ri->cmp_strcache < 0)
24240 return (cmp & CMP_LT);
24241 if(*ri->cmp_strcache > 0)
24242 return (cmp & CMP_GT);
24243 return (cmp & CMP_EQ);
24244 }
24245 else
24246 {
24247
2/2
✓ Branch 0 taken 1511 times.
✓ Branch 1 taken 1436 times.
2947 if(cmp & CMP_GT)
24248
2/2
✓ Branch 0 taken 243 times.
✓ Branch 1 taken 1193 times.
1436 if(ri->cmp_op1 > ri->cmp_op2)
24249 243 return true;
24250
2/2
✓ Branch 0 taken 1746 times.
✓ Branch 1 taken 958 times.
2704 if(cmp & CMP_LT)
24251
2/2
✓ Branch 0 taken 909 times.
✓ Branch 1 taken 49 times.
958 if(ri->cmp_op1 < ri->cmp_op2)
24252 909 return true;
24253
2/2
✓ Branch 0 taken 615 times.
✓ Branch 1 taken 1180 times.
1795 if(cmp & CMP_EQ)
24254
2/2
✓ Branch 0 taken 582 times.
✓ Branch 1 taken 598 times.
1180 if(ri->cmp_op1 == ri->cmp_op2)
24255 582 return true;
24256 1213 return false;
24257 }
24258 2947 }
24259
24260 4248 static void markRegisterType(int reg, int type)
24261 {
24262 // Currently only marking globals as objects is supported.
24263
1/2
✓ Branch 0 taken 4248 times.
✗ Branch 1 not taken.
4248 if (!(reg >= GD(0) && reg <= GD(MAX_SCRIPT_REGISTERS)))
24264 {
24265 assert(false);
24266 }
24267
1/2
✓ Branch 0 taken 4248 times.
✗ Branch 1 not taken.
4248 if (!(type >= 0 && type <= (int)script_object_type::last))
24268 {
24269 assert(false);
24270 }
24271
24272 4248 int index = reg - GD(0);
24273 4248 game->global_d_types[index] = (script_object_type)type;
24274 4248 }
24275
24276 1077 static void markGlobalRegisters()
24277 {
24278 word scommand;
24279 1077 auto& init_script = *globalscripts[GLOBAL_SCRIPT_INIT];
24280
2/2
✓ Branch 0 taken 650 times.
✓ Branch 1 taken 427 times.
1077 if (!init_script.valid())
24281 427 return;
24282
24283 650 auto& zasm = init_script.zasm_script->zasm;
24284 650 uint32_t start_pc = init_script.pc, end_pc = init_script.end_pc;
24285
24286
2/2
✓ Branch 0 taken 650 times.
✓ Branch 1 taken 514917 times.
515567 for (auto pc = start_pc; pc < end_pc; pc++)
24287 {
24288 514917 scommand = zasm[pc].command;
24289
2/2
✓ Branch 0 taken 512718 times.
✓ Branch 1 taken 2199 times.
514917 if(scommand == MARK_TYPE_REG)
24290 2199 markRegisterType(zasm[pc].arg1, zasm[pc].arg2);
24291 514917 }
24292 1077 }
24293
24294 void goto_err(char const* opname)
24295 {
24296 auto i = curScriptIndex;
24297 const char* type_str = ScriptTypeToString(curScriptType);
24298 switch(curScriptType)
24299 {
24300 case ScriptType::FFC:
24301 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, ffcmap[i].scriptname.c_str(), opname, sarg1); break;
24302 case ScriptType::NPC:
24303 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, npcmap[i].scriptname.c_str(), opname, sarg1); break;
24304 case ScriptType::Lwpn:
24305 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, lwpnmap[i].scriptname.c_str(), opname, sarg1); break;
24306 case ScriptType::Ewpn:
24307 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, ewpnmap[i].scriptname.c_str(), opname, sarg1); break;
24308 case ScriptType::ItemSprite:
24309 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, itemspritemap[i].scriptname.c_str(), opname, sarg1); break;
24310 case ScriptType::Item:
24311 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, itemmap[i].scriptname.c_str(), opname, sarg1); break;
24312 case ScriptType::Global:
24313 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, globalmap[i].scriptname.c_str(), opname, sarg1); break;
24314 case ScriptType::Hero:
24315 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, playermap[i].scriptname.c_str(), opname, sarg1); break;
24316 case ScriptType::Screen:
24317 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, screenmap[i].scriptname.c_str(), opname, sarg1); break;
24318 case ScriptType::OnMap:
24319 case ScriptType::DMap:
24320 case ScriptType::ScriptedActiveSubscreen:
24321 case ScriptType::ScriptedPassiveSubscreen:
24322 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, dmapmap[i].scriptname.c_str(), opname, sarg1); break;
24323 case ScriptType::Combo:
24324 Z_scripterrlog("%s Script %s attempted to %s an invalid jump to (%d).\n", type_str, comboscriptmap[i].scriptname.c_str(), opname, sarg1); break;
24325
24326 default: break;
24327 }
24328 }
24329
24330 85426 static void script_exit_cleanup(bool no_dealloc)
24331 {
24332 85426 ScriptType type = curScriptType;
24333 85426 word script = curScriptNum;
24334 85426 int32_t i = curScriptIndex;
24335
24336
8/9
✓ Branch 0 taken 10466 times.
✓ Branch 1 taken 62522 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10210 times.
✓ Branch 4 taken 81 times.
✓ Branch 5 taken 49 times.
✓ Branch 6 taken 39 times.
✓ Branch 7 taken 10 times.
✓ Branch 8 taken 2049 times.
85426 switch(type)
24337 {
24338 case ScriptType::FFC:
24339 {
24340
1/2
✓ Branch 0 taken 10210 times.
✗ Branch 1 not taken.
10210 if (auto ffc = ResolveFFCWithID(i))
24341 10210 ffc->script = 0;
24342 10210 auto& data = get_script_engine_data(type, i);
24343 10210 data.doscript = false;
24344 }
24345 10210 break;
24346
24347 case ScriptType::Screen:
24348 81 get_scr(i)->script = 0;
24349 case ScriptType::Global:
24350 case ScriptType::Hero:
24351 case ScriptType::DMap:
24352 case ScriptType::OnMap:
24353 case ScriptType::ScriptedActiveSubscreen:
24354 case ScriptType::ScriptedPassiveSubscreen:
24355 case ScriptType::EngineSubscreen:
24356 case ScriptType::Combo:
24357 {
24358 10547 auto& data = get_script_engine_data(type, i);
24359 10547 data.doscript = false;
24360 }
24361 10547 break;
24362 case ScriptType::Ewpn:
24363 case ScriptType::Lwpn:
24364 case ScriptType::NPC:
24365 {
24366 62522 auto& data = get_script_engine_data(type, i);
24367 62522 data.doscript = false;
24368 62522 data.initialized = false;
24369
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62522 times.
62522 if (auto spr = sprite::getByUID(i))
24370 62522 spr->weaponscript = 0;
24371 }
24372 62522 break;
24373 case ScriptType::ItemSprite:
24374 {
24375 49 auto& data = get_script_engine_data(type, i);
24376 49 data.doscript = false;
24377 49 data.initialized = false;
24378
1/2
✓ Branch 0 taken 49 times.
✗ Branch 1 not taken.
49 if (auto spr = sprite::getByUID(i))
24379 49 spr->script = 0;
24380 }
24381 49 break;
24382
24383 case ScriptType::Generic:
24384 39 user_genscript::get(script).quit();
24385 39 break;
24386
24387 case ScriptType::GenericFrozen:
24388 10 FFCore.doscript(ScriptType::GenericFrozen, gen_frozen_index-1) = false;
24389 10 break;
24390
24391 case ScriptType::Item:
24392 {
24393
2/2
✓ Branch 0 taken 1742 times.
✓ Branch 1 taken 307 times.
2049 bool collect = ( ( i < 1 ) || (i == COLLECT_SCRIPT_ITEM_ZERO) );
24394
3/4
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 1742 times.
✓ Branch 2 taken 307 times.
✗ Branch 3 not taken.
2049 int new_i = ( collect ) ? (( i != COLLECT_SCRIPT_ITEM_ZERO ) ? (i * -1) : 0) : i;
24395 2049 auto& data = get_script_engine_data(ScriptType::Item, i);
24396
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 1742 times.
2049 if ( !collect )
24397 {
24398
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1742 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1742 if ( (itemsbuf[i].flags&item_passive_script) && game->item[i] ) itemsbuf[i].script = 0; //Quit perpetual scripts, too.
24399 1742 data.doscript = 0;
24400 1742 data.ref.Clear();
24401 1742 }
24402 else
24403 {
24404 307 data.doscript = 0;
24405 307 data.ref.Clear();
24406 }
24407 2049 data.initialized = false;
24408 2049 break;
24409 }
24410 }
24411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 85426 times.
85426 if(!no_dealloc)
24412
2/2
✓ Branch 0 taken 83377 times.
✓ Branch 1 taken 2049 times.
85426 switch(type)
24413 {
24414 case ScriptType::Item:
24415 {
24416
2/2
✓ Branch 0 taken 1742 times.
✓ Branch 1 taken 307 times.
2049 bool collect = ( ( i < 1 ) || (i == COLLECT_SCRIPT_ITEM_ZERO) );
24417
3/4
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 1742 times.
✓ Branch 2 taken 307 times.
✗ Branch 3 not taken.
2049 int new_i = ( collect ) ? (( i != COLLECT_SCRIPT_ITEM_ZERO ) ? (i * -1) : 0) : i;
24418 2049 FFScript::deallocateAllScriptOwned(ScriptType::Item, new_i);
24419 2049 break;
24420 }
24421
24422 default:
24423 83377 FFScript::deallocateAllScriptOwned(type, i);
24424 83377 break;
24425 85426 }
24426 85426 }
24427
24428 30540600 int32_t run_script(ScriptType type, word script, int32_t i)
24429 {
24430
3/4
✓ Branch 0 taken 30540600 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 71 times.
✓ Branch 3 taken 30540529 times.
30540600 if(Quit==qRESET || Quit==qEXIT) // In case an earlier script hung
24431 71 return RUNSCRIPT_ERROR;
24432
24433
4/4
✓ Branch 0 taken 19427391 times.
✓ Branch 1 taken 11113138 times.
✓ Branch 2 taken 15556747 times.
✓ Branch 3 taken 3870644 times.
30540529 if(type != ScriptType::Global && !script) return RUNSCRIPT_OK; //Safeguard against running null scripts
24434
24435 26669885 combopos_modified = -1;
24436 26669885 curScriptType=type;
24437 26669885 curScriptNum=script;
24438 26669885 curScriptIndex=i;
24439 26669885 current_zasm_register=0;
24440 //numInstructions=0; //DON'T CLEAR THIS OR IT CAN HARDLOCK! -Em
24441
24442
2/4
✓ Branch 0 taken 26669885 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 26669885 times.
26669885 if (!(type >= ScriptType::First && type <= ScriptType::Last))
24443 {
24444 al_trace("Invalid script type: %d\n", (int)type);
24445 return RUNSCRIPT_ERROR;
24446 }
24447
24448 26669885 bool got_initialized = false;
24449
1/2
✓ Branch 0 taken 26669885 times.
✗ Branch 1 not taken.
26669885 switch(type)
24450 {
24451 case ScriptType::FFC:
24452 case ScriptType::Global:
24453 case ScriptType::Hero:
24454 case ScriptType::DMap:
24455 case ScriptType::OnMap:
24456 case ScriptType::ScriptedActiveSubscreen:
24457 case ScriptType::ScriptedPassiveSubscreen:
24458 case ScriptType::EngineSubscreen:
24459 case ScriptType::Screen:
24460 case ScriptType::Combo:
24461 case ScriptType::Item:
24462 case ScriptType::NPC:
24463 case ScriptType::Lwpn:
24464 case ScriptType::Ewpn:
24465 case ScriptType::ItemSprite:
24466 case ScriptType::Generic:
24467 case ScriptType::GenericFrozen:
24468 {
24469 26669885 got_initialized = set_current_script_engine_data(type, script, i);
24470 }
24471 26669885 break;
24472
24473 default:
24474 {
24475 al_trace("No other scripts are currently supported\n");
24476 return RUNSCRIPT_ERROR;
24477 }
24478 }
24479
24480 // Because qst.cpp likes to write script_data without setting this.
24481 26669885 curscript->meta.script_type = type;
24482
24483 // If script isn't valid, we don't have a `pc` to start from... just exit.
24484
2/2
✓ Branch 0 taken 26667193 times.
✓ Branch 1 taken 2692 times.
26669885 if(!curscript->valid())
24485 {
24486 2692 script_exit_cleanup(false);
24487 2692 return RUNSCRIPT_OK;
24488 }
24489
24490 26667193 script_funcrun = false;
24491
24492 26667193 JittedScriptHandle* jitted_script = nullptr;
24493
2/2
✓ Branch 0 taken 26667189 times.
✓ Branch 1 taken 4 times.
26667193 if (jit_is_enabled())
24494 {
24495 26667189 auto key = std::make_pair(curscript, ri);
24496 26667189 auto it = jitted_scripts.find(key);
24497
2/2
✓ Branch 0 taken 79433 times.
✓ Branch 1 taken 26587756 times.
26667189 if (it == jitted_scripts.end())
24498 {
24499 79433 jitted_scripts[key] = jitted_script = jit_create_script_handle(curscript, ri);
24500 79433 }
24501 else
24502 {
24503 26587756 jitted_script = it->second;
24504 }
24505 26667189 }
24506
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
4 else if (zasm_optimize_enabled() && curscript->valid() && !curscript->zasm_script->optimized)
24507 {
24508 zasm_optimize_and_log(curscript->zasm_script.get());
24509 }
24510
24511 26667193 runtime_script_debug_handle = nullptr;
24512
1/2
✓ Branch 0 taken 26667193 times.
✗ Branch 1 not taken.
26667193 if (script_debug_is_runtime_debugging())
24513 {
24514 if (!script_debug_handles.contains(curscript->id))
24515 {
24516 script_debug_handles.emplace(curscript->id, ScriptDebugHandle(
24517 curscript->zasm_script.get(), ScriptDebugHandle::OutputSplit::ByFrame, curscript->name()));
24518 }
24519 runtime_script_debug_handle = &script_debug_handles.at(curscript->id);
24520 runtime_script_debug_handle->update_file();
24521 std::string line = fmt::format("=== running script type: {} index: {} name: {} i: {} script: {}", ScriptTypeToString(curscript->id.type), curscript->id.index, curscript->meta.script_name, i, script);
24522 runtime_script_debug_handle->print("\n");
24523 runtime_script_debug_handle->print(line.c_str());
24524 runtime_script_debug_handle->print("\n");
24525
24526 replay_step_comment(line);
24527 }
24528
1/2
✓ Branch 0 taken 26667193 times.
✗ Branch 1 not taken.
26667193 if (script_debug_is_runtime_debugging() == 1)
24529 {
24530 std::string line = script_debug_registers_and_stack_to_string();
24531 runtime_script_debug_handle->print(line.c_str());
24532 runtime_script_debug_handle->print("\n");
24533
24534 util::replchar(line, '\n', ' ');
24535 replay_step_comment(line);
24536 }
24537
24538 int32_t result;
24539
2/2
✓ Branch 0 taken 26667186 times.
✓ Branch 1 taken 7 times.
26667193 if (jitted_script)
24540 {
24541
2/2
✓ Branch 0 taken 26564207 times.
✓ Branch 1 taken 102979 times.
26667186 if (got_initialized)
24542 102979 jit_reinit(jitted_script);
24543
2/2
✓ Branch 0 taken 30148 times.
✓ Branch 1 taken 26637038 times.
26667186 if (ri->waitframes)
24544 {
24545 30148 --ri->waitframes;
24546 30148 result = RUNSCRIPT_OK;
24547 30148 }
24548 else
24549 {
24550 26637038 result = jit_run_script(jitted_script);
24551 }
24552 26667186 }
24553 else
24554 {
24555 7 result = run_script_int(false);
24556 }
24557
24558
2/2
✓ Branch 0 taken 24306354 times.
✓ Branch 1 taken 2360839 times.
26667193 if (ZScriptVersion::gc())
24559 {
24560 // Drain the autorelease pool.
24561 // Move the vector, since destructors can possibly
24562 // create objects and modify `script_object_autorelease_pool`.
24563 2360839 auto ids = std::move(script_object_autorelease_pool);
24564
2/2
✓ Branch 0 taken 2360839 times.
✓ Branch 1 taken 37077 times.
2397916 for (auto id : ids)
24565
1/2
✓ Branch 0 taken 37077 times.
✗ Branch 1 not taken.
37077 script_object_ref_dec(id);
24566
24567 // This throttles the actual full GC run.
24568
1/2
✓ Branch 0 taken 2360839 times.
✗ Branch 1 not taken.
2360839 maybe_run_gc();
24569 2360839 }
24570
24571
6/16
✗ Branch 0 not taken.
✓ Branch 1 taken 26667193 times.
✓ Branch 2 taken 26667193 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 26667193 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 26667193 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 26667193 times.
✓ Branch 10 taken 26667193 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
53334386 if (replay_is_active() && replay_get_meta_bool("debug_script_state"))
24572 {
24573 std::string str = script_debug_registers_and_stack_to_string();
24574 util::replstr(str, "\n", " ");
24575 replay_step_comment(str);
24576 }
24577
24578
1/2
✓ Branch 0 taken 26667193 times.
✗ Branch 1 not taken.
26667193 if (runtime_script_debug_handle)
24579 {
24580 runtime_script_debug_handle->print(fmt::format("result: {}\n", result).c_str());
24581 replay_step_comment(fmt::format("result: {}", result));
24582 }
24583 26667193 return result;
24584 30540600 }
24585
24586 1166139758 int32_t run_script_int(bool is_jitted)
24587 {
24588 1166139758 ScriptType type = curScriptType;
24589 1166139758 word script = curScriptNum;
24590 1166139758 int32_t i = curScriptIndex;
24591
24592 1166139758 current_zasm_command=(ASM_DEFINE)0; // this is actually SETV, but we never will print that as a context string, so it's fine.
24593
24594 1166139758 int commands_run = 0;
24595 1166139758 int jit_waiting_nop = false;
24596
2/2
✓ Branch 0 taken 1166138948 times.
✓ Branch 1 taken 810 times.
1166139758 bool old_script_funcrun = script_funcrun && curscript->meta.ffscript_v < 23;
24597
2/2
✓ Branch 0 taken 1166138941 times.
✓ Branch 1 taken 817 times.
1166139758 if(!is_jitted)
24598 {
24599
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 817 times.
817 if(ri->waitframes)
24600 {
24601 --ri->waitframes;
24602 return RUNSCRIPT_OK;
24603 }
24604 817 zs_vargs.clear();
24605
24606 #ifdef _FFDISSASSEMBLY
24607
24608 if(curscript->zasm[ri->pc].command != 0xFFFF)
24609 {
24610 #ifdef _FFONESCRIPTDISSASSEMBLY
24611 zc_trace_clear();
24612 #endif
24613
24614 switch(type)
24615 {
24616 case ScriptType::FFC:
24617 al_trace("\nStart of FFC script %i processing on FFC %i:\n", script, i);
24618 break;
24619
24620 case ScriptType::Item:
24621 al_trace("\nStart of item script %i processing:\n", script);
24622 break;
24623
24624 case ScriptType::Global:
24625 al_trace("\nStart of global script %I processing:\n", script);
24626 break;
24627 }
24628 }
24629
24630 #endif
24631 817 }
24632 //j_command
24633 1166139758 bool is_debugging = script_debug_is_runtime_debugging() == 2;
24634 1166139758 bool increment = true;
24635
5/8
✓ Branch 0 taken 220 times.
✓ Branch 1 taken 1166139538 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 220 times.
✓ Branch 4 taken 220 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 220 times.
✗ Branch 7 not taken.
1166139758 static std::vector<ffscript> empty_zasm = {{0xFFFF}};
24636
1/2
✓ Branch 0 taken 1166139758 times.
✗ Branch 1 not taken.
1166139758 const auto& zasm = curscript->valid() ? curscript->zasm_script->zasm : empty_zasm;
24637 1166139758 word scommand = zasm[ri->pc].command;
24638 1166139758 bool hit_invalid_zasm = false;
24639 1166139758 bool no_dealloc = false;
24640
2/2
✓ Branch 0 taken 842 times.
✓ Branch 1 taken 1174848973 times.
1174849815 while(scommand != 0xFFFF)
24641 {
24642 1174848973 const auto& op = zasm[ri->pc];
24643 1174848973 scommand = op.command;
24644 1174848973 sarg1 = op.arg1;
24645 1174848973 sarg2 = op.arg2;
24646 1174848973 sarg3 = op.arg3;
24647 1174848973 sargstr = op.strptr;
24648 1174848973 sargvec = op.vecptr;
24649
24650 1174848973 current_zasm_command = (ASM_DEFINE)op.command;
24651
24652
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1174848973 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1174848973 if (is_debugging && (!is_jitted || commands_run > 0))
24653 {
24654 runtime_script_debug_handle->pre_command();
24655 }
24656
24657 1174848973 bool waiting = true;
24658
6/6
✓ Branch 0 taken 1148293989 times.
✓ Branch 1 taken 6048408 times.
✓ Branch 2 taken 977482 times.
✓ Branch 3 taken 3138 times.
✓ Branch 4 taken 19523913 times.
✓ Branch 5 taken 2043 times.
1174848973 switch(scommand) //Handle waitframe-type commands first
24659 {
24660 case WAITDRAW:
24661 {
24662
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6048408 times.
6048408 if(script_funcrun)
24663 scommand = NOP;
24664
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 6048408 times.
✗ Branch 2 not taken.
6048408 else switch(type)
24665 {
24666 case ScriptType::EngineSubscreen: //ignore waitdraws
24667 Z_scripterrlog("'Waitdraw()' is invalid in subscreen scripts, will be ignored\n");
24668 scommand = NOP;
24669 break;
24670 case ScriptType::Generic:
24671 case ScriptType::GenericFrozen: //ignore waitdraws
24672 Z_scripterrlog("'Waitdraw()' is invalid in generic scripts, will be ignored\n");
24673 scommand = NOP;
24674 break;
24675 }
24676 6048408 break;
24677 }
24678 case WAITTO:
24679 {
24680
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 977482 times.
977482 if(script_funcrun)
24681 scommand = NOP;
24682
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 977482 times.
977482 else switch(type)
24683 {
24684 case ScriptType::GenericFrozen:
24685 //ignore, no warn/error
24686 scommand = NOP;
24687 break;
24688 case ScriptType::Generic:
24689 {
24690 977482 user_genscript& scr = user_genscript::get(script);
24691 977482 int32_t target = get_register(sarg1)/10000L;
24692 977482 bool atleast = get_register(sarg2)!=0;
24693
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 977482 times.
977482 if(unsigned(target) > SCR_TIMING_END_FRAME)
24694 {
24695 Z_scripterrlog("Invalid value '%d' provided to 'WaitTo()'\n", target);
24696 scommand = NOP;
24697 break;
24698 }
24699
2/4
✓ Branch 0 taken 977481 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
977482 if(genscript_timing == target ||
24700
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 977481 times.
977481 (atleast && genscript_timing < target))
24701 {
24702 //Already that time, skip the command
24703 1 scommand = NOP;
24704 1 break;
24705 }
24706 977481 scr.waituntil = scr_timing(target);
24707 977481 scr.wait_atleast = atleast;
24708 977481 break;
24709 }
24710 default:
24711 Z_scripterrlog("'WaitTo()' is only valid in 'generic' scripts!\n");
24712 scommand = NOP;
24713 break;
24714 }
24715 977482 break;
24716 }
24717 case WAITEVENT:
24718 {
24719
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3138 times.
3138 if(script_funcrun)
24720 scommand = NOP;
24721
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 3138 times.
3138 else switch(type)
24722 {
24723 case ScriptType::GenericFrozen:
24724 scommand = WAITFRAME;
24725 ri->d[0] = GENSCR_EVENT_NIL*10000; //no event
24726 break;
24727 case ScriptType::Generic:
24728 {
24729 3138 user_genscript& scr = user_genscript::get(script);
24730 3138 scr.waitevent = true;
24731 3138 break;
24732 }
24733 default:
24734 Z_scripterrlog("'WaitEvent()' is only valid in 'generic' scripts!\n");
24735 scommand = NOP;
24736 break;
24737 }
24738 3138 break;
24739 }
24740 case WAITFRAME:
24741 {
24742
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19523913 times.
19523913 if(script_funcrun)
24743 scommand = NOP;
24744
2/2
✓ Branch 0 taken 18365637 times.
✓ Branch 1 taken 1158276 times.
19523913 else switch(type)
24745 {
24746 case ScriptType::Generic:
24747 {
24748 1158276 user_genscript& scr = user_genscript::get(script);
24749 1158276 scr.waituntil = SCR_TIMING_START_FRAME;
24750 1158276 scr.wait_atleast = false;
24751 1158276 break;
24752 }
24753 }
24754 19523913 break;
24755 }
24756 case WAITFRAMESR:
24757 {
24758 2043 auto count = get_register(sarg1);
24759
3/4
✓ Branch 0 taken 2043 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 690 times.
✓ Branch 3 taken 1353 times.
2043 if(script_funcrun || count <= 0)
24760 {
24761 690 scommand = NOP;
24762 690 break;
24763 }
24764 1353 auto frames = count/10000;
24765
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1353 times.
1353 if(count%10000) ++frames; //round up decimals
24766 1353 ri->waitframes = frames-1; //this frame doesn't count
24767
2/2
✓ Branch 0 taken 1054 times.
✓ Branch 1 taken 299 times.
1353 switch(type)
24768 {
24769 case ScriptType::Generic:
24770 {
24771 299 user_genscript& scr = user_genscript::get(script);
24772 299 scr.waituntil = SCR_TIMING_START_FRAME;
24773 299 scr.wait_atleast = false;
24774 299 break;
24775 }
24776 }
24777 1353 break;
24778 }
24779 1148293989 default: waiting = false;
24780 1148293989 }
24781
4/4
✓ Branch 0 taken 26554984 times.
✓ Branch 1 taken 1148293989 times.
✓ Branch 2 taken 26554293 times.
✓ Branch 3 taken 691 times.
1174848973 if(waiting && scommand != NOP)
24782 {
24783
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26554293 times.
26554293 if (is_jitted)
24784 26554293 jit_waiting_nop = true;
24785 26554293 break;
24786 }
24787
24788 1148294680 numInstructions++;
24789
2/2
✓ Branch 0 taken 1147146462 times.
✓ Branch 1 taken 1148218 times.
1148294680 if(numInstructions==hangcount) // No need to check frequently
24790 {
24791 1148218 numInstructions=0;
24792 1148218 poll_keyboard();
24793 1148218 checkQuitKeys();
24794
1/2
✓ Branch 0 taken 1148218 times.
✗ Branch 1 not taken.
1148218 if(Quit)
24795 scommand=0xFFFF;
24796 1148218 }
24797
24798
246/880
✓ Branch 0 taken 82664 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 61 times.
✓ Branch 4 taken 50 times.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2313 times.
✓ Branch 8 taken 13768058 times.
✓ Branch 9 taken 5 times.
✓ Branch 10 taken 13 times.
✓ Branch 11 taken 1714 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 9550421 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 1480 times.
✓ Branch 17 taken 14918 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 17821 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 14 times.
✓ Branch 23 taken 4797 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✓ Branch 35 taken 1649936 times.
✗ Branch 36 not taken.
✓ Branch 37 taken 15 times.
✓ Branch 38 taken 6556 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 43 taken 1129056 times.
✓ Branch 44 taken 678025 times.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✓ Branch 48 taken 4677945 times.
✓ Branch 49 taken 34306 times.
✓ Branch 50 taken 10744 times.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✓ Branch 53 taken 12 times.
✓ Branch 54 taken 2 times.
✓ Branch 55 taken 15 times.
✓ Branch 56 taken 3 times.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✓ Branch 59 taken 5660 times.
✗ Branch 60 not taken.
✓ Branch 61 taken 2004 times.
✗ Branch 62 not taken.
✓ Branch 63 taken 178 times.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✓ Branch 68 taken 1452537 times.
✓ Branch 69 taken 5620654 times.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✓ Branch 72 taken 432438 times.
✓ Branch 73 taken 3209679 times.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✓ Branch 77 taken 223 times.
✓ Branch 78 taken 11 times.
✓ Branch 79 taken 24 times.
✓ Branch 80 taken 87 times.
✓ Branch 81 taken 92 times.
✓ Branch 82 taken 234 times.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✓ Branch 92 taken 27870027 times.
✓ Branch 93 taken 22444 times.
✗ Branch 94 not taken.
✓ Branch 95 taken 5 times.
✓ Branch 96 taken 160009 times.
✗ Branch 97 not taken.
✓ Branch 98 taken 19653 times.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✗ Branch 101 not taken.
✓ Branch 102 taken 257 times.
✓ Branch 103 taken 5 times.
✓ Branch 104 taken 354947 times.
✓ Branch 105 taken 3 times.
✗ Branch 106 not taken.
✓ Branch 107 taken 354994 times.
✓ Branch 108 taken 357 times.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✓ Branch 111 taken 3062 times.
✓ Branch 112 taken 3512 times.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✗ Branch 115 not taken.
✓ Branch 116 taken 10 times.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✗ Branch 119 not taken.
✗ Branch 120 not taken.
✗ Branch 121 not taken.
✗ Branch 122 not taken.
✗ Branch 123 not taken.
✗ Branch 124 not taken.
✓ Branch 125 taken 7069332 times.
✗ Branch 126 not taken.
✗ Branch 127 not taken.
✗ Branch 128 not taken.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✓ Branch 132 taken 66 times.
✓ Branch 133 taken 92 times.
✗ Branch 134 not taken.
✓ Branch 135 taken 3596 times.
✗ Branch 136 not taken.
✓ Branch 137 taken 440764 times.
✗ Branch 138 not taken.
✗ Branch 139 not taken.
✗ Branch 140 not taken.
✗ Branch 141 not taken.
✗ Branch 142 not taken.
✗ Branch 143 not taken.
✗ Branch 144 not taken.
✗ Branch 145 not taken.
✗ Branch 146 not taken.
✗ Branch 147 not taken.
✗ Branch 148 not taken.
✗ Branch 149 not taken.
✗ Branch 150 not taken.
✗ Branch 151 not taken.
✗ Branch 152 not taken.
✗ Branch 153 not taken.
✗ Branch 154 not taken.
✗ Branch 155 not taken.
✗ Branch 156 not taken.
✗ Branch 157 not taken.
✗ Branch 158 not taken.
✗ Branch 159 not taken.
✗ Branch 160 not taken.
✗ Branch 161 not taken.
✗ Branch 162 not taken.
✗ Branch 163 not taken.
✗ Branch 164 not taken.
✗ Branch 165 not taken.
✗ Branch 166 not taken.
✗ Branch 167 not taken.
✗ Branch 168 not taken.
✗ Branch 169 not taken.
✗ Branch 170 not taken.
✗ Branch 171 not taken.
✗ Branch 172 not taken.
✗ Branch 173 not taken.
✗ Branch 174 not taken.
✗ Branch 175 not taken.
✗ Branch 176 not taken.
✗ Branch 177 not taken.
✗ Branch 178 not taken.
✗ Branch 179 not taken.
✗ Branch 180 not taken.
✗ Branch 181 not taken.
✗ Branch 182 not taken.
✗ Branch 183 not taken.
✗ Branch 184 not taken.
✗ Branch 185 not taken.
✗ Branch 186 not taken.
✗ Branch 187 not taken.
✗ Branch 188 not taken.
✗ Branch 189 not taken.
✗ Branch 190 not taken.
✗ Branch 191 not taken.
✗ Branch 192 not taken.
✗ Branch 193 not taken.
✗ Branch 194 not taken.
✗ Branch 195 not taken.
✗ Branch 196 not taken.
✗ Branch 197 not taken.
✗ Branch 198 not taken.
✗ Branch 199 not taken.
✗ Branch 200 not taken.
✗ Branch 201 not taken.
✗ Branch 202 not taken.
✗ Branch 203 not taken.
✗ Branch 204 not taken.
✗ Branch 205 not taken.
✗ Branch 206 not taken.
✗ Branch 207 not taken.
✗ Branch 208 not taken.
✗ Branch 209 not taken.
✗ Branch 210 not taken.
✗ Branch 211 not taken.
✗ Branch 212 not taken.
✗ Branch 213 not taken.
✗ Branch 214 not taken.
✗ Branch 215 not taken.
✗ Branch 216 not taken.
✗ Branch 217 not taken.
✗ Branch 218 not taken.
✗ Branch 219 not taken.
✗ Branch 220 not taken.
✗ Branch 221 not taken.
✗ Branch 222 not taken.
✗ Branch 223 not taken.
✗ Branch 224 not taken.
✗ Branch 225 not taken.
✗ Branch 226 not taken.
✗ Branch 227 not taken.
✓ Branch 228 taken 3 times.
✓ Branch 229 taken 5 times.
✗ Branch 230 not taken.
✗ Branch 231 not taken.
✗ Branch 232 not taken.
✓ Branch 233 taken 7 times.
✗ Branch 234 not taken.
✗ Branch 235 not taken.
✓ Branch 236 taken 1 times.
✓ Branch 237 taken 1 times.
✗ Branch 238 not taken.
✗ Branch 239 not taken.
✗ Branch 240 not taken.
✗ Branch 241 not taken.
✗ Branch 242 not taken.
✓ Branch 243 taken 73 times.
✓ Branch 244 taken 6 times.
✗ Branch 245 not taken.
✗ Branch 246 not taken.
✗ Branch 247 not taken.
✓ Branch 248 taken 828 times.
✗ Branch 249 not taken.
✗ Branch 250 not taken.
✗ Branch 251 not taken.
✓ Branch 252 taken 2049 times.
✓ Branch 253 taken 53639074 times.
✓ Branch 254 taken 45321202 times.
✗ Branch 255 not taken.
✗ Branch 256 not taken.
✓ Branch 257 taken 1665401 times.
✗ Branch 258 not taken.
✗ Branch 259 not taken.
✓ Branch 260 taken 12822 times.
✓ Branch 261 taken 958 times.
✓ Branch 262 taken 8 times.
✓ Branch 263 taken 11 times.
✗ Branch 264 not taken.
✓ Branch 265 taken 3 times.
✗ Branch 266 not taken.
✓ Branch 267 taken 1974 times.
✓ Branch 268 taken 932 times.
✓ Branch 269 taken 65 times.
✓ Branch 270 taken 875 times.
✗ Branch 271 not taken.
✗ Branch 272 not taken.
✓ Branch 273 taken 4 times.
✓ Branch 274 taken 12 times.
✓ Branch 275 taken 4 times.
✗ Branch 276 not taken.
✓ Branch 277 taken 2 times.
✗ Branch 278 not taken.
✓ Branch 279 taken 5 times.
✗ Branch 280 not taken.
✓ Branch 281 taken 151435890 times.
✓ Branch 282 taken 81453903 times.
✓ Branch 283 taken 50482178 times.
✗ Branch 284 not taken.
✓ Branch 285 taken 80746848 times.
✓ Branch 286 taken 2929235 times.
✓ Branch 287 taken 3240415 times.
✓ Branch 288 taken 560049 times.
✗ Branch 289 not taken.
✓ Branch 290 taken 603 times.
✗ Branch 291 not taken.
✓ Branch 292 taken 1410 times.
✗ Branch 293 not taken.
✓ Branch 294 taken 2451 times.
✓ Branch 295 taken 2833 times.
✓ Branch 296 taken 4382 times.
✓ Branch 297 taken 1454 times.
✗ Branch 298 not taken.
✗ Branch 299 not taken.
✗ Branch 300 not taken.
✓ Branch 301 taken 5548 times.
✓ Branch 302 taken 25 times.
✗ Branch 303 not taken.
✗ Branch 304 not taken.
✓ Branch 305 taken 6044 times.
✗ Branch 306 not taken.
✗ Branch 307 not taken.
✓ Branch 308 taken 2162 times.
✗ Branch 309 not taken.
✗ Branch 310 not taken.
✗ Branch 311 not taken.
✗ Branch 312 not taken.
✗ Branch 313 not taken.
✓ Branch 314 taken 13656676 times.
✓ Branch 315 taken 10 times.
✗ Branch 316 not taken.
✓ Branch 317 taken 303069076 times.
✓ Branch 318 taken 10105619 times.
✓ Branch 319 taken 80 times.
✓ Branch 320 taken 3358320 times.
✗ Branch 321 not taken.
✓ Branch 322 taken 4 times.
✓ Branch 323 taken 987 times.
✓ Branch 324 taken 804 times.
✓ Branch 325 taken 6 times.
✓ Branch 326 taken 432 times.
✓ Branch 327 taken 564 times.
✗ Branch 328 not taken.
✗ Branch 329 not taken.
✓ Branch 330 taken 7 times.
✗ Branch 331 not taken.
✗ Branch 332 not taken.
✓ Branch 333 taken 415 times.
✗ Branch 334 not taken.
✓ Branch 335 taken 6483138 times.
✓ Branch 336 taken 100 times.
✓ Branch 337 taken 138537 times.
✓ Branch 338 taken 6050 times.
✓ Branch 339 taken 5879938 times.
✓ Branch 340 taken 6352 times.
✓ Branch 341 taken 37547 times.
✗ Branch 342 not taken.
✗ Branch 343 not taken.
✓ Branch 344 taken 499288 times.
✓ Branch 345 taken 16 times.
✓ Branch 346 taken 2541 times.
✗ Branch 347 not taken.
✓ Branch 348 taken 2925 times.
✓ Branch 349 taken 2 times.
✗ Branch 350 not taken.
✗ Branch 351 not taken.
✗ Branch 352 not taken.
✗ Branch 353 not taken.
✗ Branch 354 not taken.
✗ Branch 355 not taken.
✗ Branch 356 not taken.
✓ Branch 357 taken 56 times.
✓ Branch 358 taken 935 times.
✗ Branch 359 not taken.
✗ Branch 360 not taken.
✗ Branch 361 not taken.
✗ Branch 362 not taken.
✗ Branch 363 not taken.
✗ Branch 364 not taken.
✗ Branch 365 not taken.
✗ Branch 366 not taken.
✓ Branch 367 taken 1707 times.
✓ Branch 368 taken 1664 times.
✓ Branch 369 taken 137111 times.
✗ Branch 370 not taken.
✓ Branch 371 taken 105 times.
✓ Branch 372 taken 31 times.
✗ Branch 373 not taken.
✗ Branch 374 not taken.
✗ Branch 375 not taken.
✗ Branch 376 not taken.
✗ Branch 377 not taken.
✗ Branch 378 not taken.
✗ Branch 379 not taken.
✗ Branch 380 not taken.
✓ Branch 381 taken 2397 times.
✓ Branch 382 taken 1520226 times.
✓ Branch 383 taken 140579 times.
✓ Branch 384 taken 5 times.
✓ Branch 385 taken 30 times.
✓ Branch 386 taken 1731263 times.
✓ Branch 387 taken 2674 times.
✗ Branch 388 not taken.
✓ Branch 389 taken 2912197 times.
✗ Branch 390 not taken.
✗ Branch 391 not taken.
✗ Branch 392 not taken.
✗ Branch 393 not taken.
✗ Branch 394 not taken.
✗ Branch 395 not taken.
✓ Branch 396 taken 10089782 times.
✗ Branch 397 not taken.
✗ Branch 398 not taken.
✗ Branch 399 not taken.
✗ Branch 400 not taken.
✗ Branch 401 not taken.
✓ Branch 402 taken 969 times.
✓ Branch 403 taken 648 times.
✓ Branch 404 taken 8299299 times.
✓ Branch 405 taken 243283 times.
✗ Branch 406 not taken.
✗ Branch 407 not taken.
✗ Branch 408 not taken.
✓ Branch 409 taken 3709786 times.
✓ Branch 410 taken 73964923 times.
✓ Branch 411 taken 2752222 times.
✓ Branch 412 taken 26716589 times.
✓ Branch 413 taken 17 times.
✗ Branch 414 not taken.
✗ Branch 415 not taken.
✗ Branch 416 not taken.
✓ Branch 417 taken 22 times.
✗ Branch 418 not taken.
✓ Branch 419 taken 34296 times.
✗ Branch 420 not taken.
✓ Branch 421 taken 10283 times.
✗ Branch 422 not taken.
✓ Branch 423 taken 34 times.
✗ Branch 424 not taken.
✗ Branch 425 not taken.
✗ Branch 426 not taken.
✗ Branch 427 not taken.
✗ Branch 428 not taken.
✗ Branch 429 not taken.
✗ Branch 430 not taken.
✗ Branch 431 not taken.
✗ Branch 432 not taken.
✓ Branch 433 taken 3 times.
✓ Branch 434 taken 1373 times.
✓ Branch 435 taken 287 times.
✓ Branch 436 taken 11645 times.
✓ Branch 437 taken 33562 times.
✓ Branch 438 taken 319 times.
✗ Branch 439 not taken.
✗ Branch 440 not taken.
✗ Branch 441 not taken.
✓ Branch 442 taken 107 times.
✗ Branch 443 not taken.
✓ Branch 444 taken 127 times.
✗ Branch 445 not taken.
✓ Branch 446 taken 5436 times.
✗ Branch 447 not taken.
✗ Branch 448 not taken.
✓ Branch 449 taken 339164 times.
✗ Branch 450 not taken.
✗ Branch 451 not taken.
✗ Branch 452 not taken.
✓ Branch 453 taken 63829 times.
✓ Branch 454 taken 236 times.
✓ Branch 455 taken 140 times.
✓ Branch 456 taken 3783 times.
✓ Branch 457 taken 1 times.
✗ Branch 458 not taken.
✗ Branch 459 not taken.
✗ Branch 460 not taken.
✗ Branch 461 not taken.
✓ Branch 462 taken 14 times.
✗ Branch 463 not taken.
✗ Branch 464 not taken.
✗ Branch 465 not taken.
✗ Branch 466 not taken.
✓ Branch 467 taken 1117 times.
✗ Branch 468 not taken.
✓ Branch 469 taken 2768 times.
✗ Branch 470 not taken.
✓ Branch 471 taken 4712414 times.
✗ Branch 472 not taken.
✓ Branch 473 taken 585769 times.
✗ Branch 474 not taken.
✗ Branch 475 not taken.
✗ Branch 476 not taken.
✓ Branch 477 taken 6365 times.
✗ Branch 478 not taken.
✗ Branch 479 not taken.
✓ Branch 480 taken 177544 times.
✓ Branch 481 taken 16 times.
✗ Branch 482 not taken.
✓ Branch 483 taken 10 times.
✗ Branch 484 not taken.
✗ Branch 485 not taken.
✗ Branch 486 not taken.
✗ Branch 487 not taken.
✓ Branch 488 taken 11 times.
✗ Branch 489 not taken.
✗ Branch 490 not taken.
✗ Branch 491 not taken.
✗ Branch 492 not taken.
✓ Branch 493 taken 370 times.
✗ Branch 494 not taken.
✓ Branch 495 taken 31 times.
✗ Branch 496 not taken.
✓ Branch 497 taken 1064 times.
✓ Branch 498 taken 130 times.
✗ Branch 499 not taken.
✗ Branch 500 not taken.
✗ Branch 501 not taken.
✗ Branch 502 not taken.
✗ Branch 503 not taken.
✓ Branch 504 taken 450 times.
✓ Branch 505 taken 4781 times.
✗ Branch 506 not taken.
✓ Branch 507 taken 112 times.
✗ Branch 508 not taken.
✓ Branch 509 taken 931 times.
✓ Branch 510 taken 53 times.
✗ Branch 511 not taken.
✗ Branch 512 not taken.
✗ Branch 513 not taken.
✗ Branch 514 not taken.
✗ Branch 515 not taken.
✗ Branch 516 not taken.
✗ Branch 517 not taken.
✗ Branch 518 not taken.
✗ Branch 519 not taken.
✓ Branch 520 taken 24 times.
✗ Branch 521 not taken.
✓ Branch 522 taken 24 times.
✗ Branch 523 not taken.
✗ Branch 524 not taken.
✗ Branch 525 not taken.
✗ Branch 526 not taken.
✓ Branch 527 taken 12 times.
✓ Branch 528 taken 598 times.
✗ Branch 529 not taken.
✗ Branch 530 not taken.
✓ Branch 531 taken 87669 times.
✗ Branch 532 not taken.
✓ Branch 533 taken 209493 times.
✗ Branch 534 not taken.
✗ Branch 535 not taken.
✓ Branch 536 taken 3530 times.
✓ Branch 537 taken 587 times.
✓ Branch 538 taken 31487 times.
✓ Branch 539 taken 43 times.
✓ Branch 540 taken 11754119 times.
✓ Branch 541 taken 1205956 times.
✗ Branch 542 not taken.
✗ Branch 543 not taken.
✗ Branch 544 not taken.
✓ Branch 545 taken 208946 times.
✗ Branch 546 not taken.
✗ Branch 547 not taken.
✓ Branch 548 taken 21032557 times.
✗ Branch 549 not taken.
✗ Branch 550 not taken.
✓ Branch 551 taken 50 times.
✓ Branch 552 taken 3 times.
✓ Branch 553 taken 13670631 times.
✓ Branch 554 taken 18282859 times.
✓ Branch 555 taken 118 times.
✗ Branch 556 not taken.
✗ Branch 557 not taken.
✗ Branch 558 not taken.
✗ Branch 559 not taken.
✓ Branch 560 taken 26528 times.
✓ Branch 561 taken 146 times.
✗ Branch 562 not taken.
✗ Branch 563 not taken.
✗ Branch 564 not taken.
✗ Branch 565 not taken.
✗ Branch 566 not taken.
✗ Branch 567 not taken.
✗ Branch 568 not taken.
✗ Branch 569 not taken.
✓ Branch 570 taken 49233778 times.
✗ Branch 571 not taken.
✗ Branch 572 not taken.
✗ Branch 573 not taken.
✗ Branch 574 not taken.
✗ Branch 575 not taken.
✗ Branch 576 not taken.
✓ Branch 577 taken 57032 times.
✗ Branch 578 not taken.
✗ Branch 579 not taken.
✗ Branch 580 not taken.
✓ Branch 581 taken 4 times.
✓ Branch 582 taken 30 times.
✓ Branch 583 taken 9 times.
✗ Branch 584 not taken.
✗ Branch 585 not taken.
✓ Branch 586 taken 2 times.
✗ Branch 587 not taken.
✗ Branch 588 not taken.
✓ Branch 589 taken 30 times.
✗ Branch 590 not taken.
✗ Branch 591 not taken.
✗ Branch 592 not taken.
✗ Branch 593 not taken.
✗ Branch 594 not taken.
✗ Branch 595 not taken.
✗ Branch 596 not taken.
✗ Branch 597 not taken.
✓ Branch 598 taken 3560 times.
✗ Branch 599 not taken.
✗ Branch 600 not taken.
✗ Branch 601 not taken.
✗ Branch 602 not taken.
✗ Branch 603 not taken.
✗ Branch 604 not taken.
✗ Branch 605 not taken.
✗ Branch 606 not taken.
✗ Branch 607 not taken.
✓ Branch 608 taken 1798 times.
✗ Branch 609 not taken.
✗ Branch 610 not taken.
✗ Branch 611 not taken.
✗ Branch 612 not taken.
✗ Branch 613 not taken.
✗ Branch 614 not taken.
✗ Branch 615 not taken.
✗ Branch 616 not taken.
✗ Branch 617 not taken.
✗ Branch 618 not taken.
✗ Branch 619 not taken.
✗ Branch 620 not taken.
✗ Branch 621 not taken.
✗ Branch 622 not taken.
✗ Branch 623 not taken.
✗ Branch 624 not taken.
✗ Branch 625 not taken.
✗ Branch 626 not taken.
✗ Branch 627 not taken.
✗ Branch 628 not taken.
✗ Branch 629 not taken.
✓ Branch 630 taken 15 times.
✗ Branch 631 not taken.
✗ Branch 632 not taken.
✗ Branch 633 not taken.
✗ Branch 634 not taken.
✗ Branch 635 not taken.
✗ Branch 636 not taken.
✗ Branch 637 not taken.
✗ Branch 638 not taken.
✗ Branch 639 not taken.
✗ Branch 640 not taken.
✗ Branch 641 not taken.
✗ Branch 642 not taken.
✗ Branch 643 not taken.
✗ Branch 644 not taken.
✗ Branch 645 not taken.
✗ Branch 646 not taken.
✗ Branch 647 not taken.
✗ Branch 648 not taken.
✗ Branch 649 not taken.
✗ Branch 650 not taken.
✗ Branch 651 not taken.
✗ Branch 652 not taken.
✗ Branch 653 not taken.
✗ Branch 654 not taken.
✗ Branch 655 not taken.
✗ Branch 656 not taken.
✗ Branch 657 not taken.
✗ Branch 658 not taken.
✗ Branch 659 not taken.
✗ Branch 660 not taken.
✗ Branch 661 not taken.
✗ Branch 662 not taken.
✗ Branch 663 not taken.
✗ Branch 664 not taken.
✗ Branch 665 not taken.
✗ Branch 666 not taken.
✗ Branch 667 not taken.
✗ Branch 668 not taken.
✗ Branch 669 not taken.
✗ Branch 670 not taken.
✗ Branch 671 not taken.
✗ Branch 672 not taken.
✗ Branch 673 not taken.
✗ Branch 674 not taken.
✗ Branch 675 not taken.
✗ Branch 676 not taken.
✗ Branch 677 not taken.
✗ Branch 678 not taken.
✗ Branch 679 not taken.
✗ Branch 680 not taken.
✗ Branch 681 not taken.
✗ Branch 682 not taken.
✗ Branch 683 not taken.
✗ Branch 684 not taken.
✗ Branch 685 not taken.
✗ Branch 686 not taken.
✗ Branch 687 not taken.
✗ Branch 688 not taken.
✗ Branch 689 not taken.
✗ Branch 690 not taken.
✗ Branch 691 not taken.
✗ Branch 692 not taken.
✗ Branch 693 not taken.
✗ Branch 694 not taken.
✗ Branch 695 not taken.
✗ Branch 696 not taken.
✗ Branch 697 not taken.
✗ Branch 698 not taken.
✗ Branch 699 not taken.
✗ Branch 700 not taken.
✗ Branch 701 not taken.
✗ Branch 702 not taken.
✗ Branch 703 not taken.
✗ Branch 704 not taken.
✗ Branch 705 not taken.
✗ Branch 706 not taken.
✗ Branch 707 not taken.
✗ Branch 708 not taken.
✗ Branch 709 not taken.
✗ Branch 710 not taken.
✗ Branch 711 not taken.
✗ Branch 712 not taken.
✗ Branch 713 not taken.
✗ Branch 714 not taken.
✗ Branch 715 not taken.
✗ Branch 716 not taken.
✗ Branch 717 not taken.
✗ Branch 718 not taken.
✗ Branch 719 not taken.
✗ Branch 720 not taken.
✗ Branch 721 not taken.
✗ Branch 722 not taken.
✗ Branch 723 not taken.
✗ Branch 724 not taken.
✗ Branch 725 not taken.
✗ Branch 726 not taken.
✗ Branch 727 not taken.
✗ Branch 728 not taken.
✗ Branch 729 not taken.
✗ Branch 730 not taken.
✗ Branch 731 not taken.
✗ Branch 732 not taken.
✗ Branch 733 not taken.
✗ Branch 734 not taken.
✗ Branch 735 not taken.
✗ Branch 736 not taken.
✗ Branch 737 not taken.
✗ Branch 738 not taken.
✗ Branch 739 not taken.
✗ Branch 740 not taken.
✗ Branch 741 not taken.
✗ Branch 742 not taken.
✗ Branch 743 not taken.
✗ Branch 744 not taken.
✗ Branch 745 not taken.
✗ Branch 746 not taken.
✗ Branch 747 not taken.
✗ Branch 748 not taken.
✗ Branch 749 not taken.
✗ Branch 750 not taken.
✗ Branch 751 not taken.
✗ Branch 752 not taken.
✗ Branch 753 not taken.
✗ Branch 754 not taken.
✗ Branch 755 not taken.
✗ Branch 756 not taken.
✗ Branch 757 not taken.
✗ Branch 758 not taken.
✗ Branch 759 not taken.
✗ Branch 760 not taken.
✗ Branch 761 not taken.
✗ Branch 762 not taken.
✗ Branch 763 not taken.
✗ Branch 764 not taken.
✗ Branch 765 not taken.
✗ Branch 766 not taken.
✗ Branch 767 not taken.
✗ Branch 768 not taken.
✗ Branch 769 not taken.
✗ Branch 770 not taken.
✗ Branch 771 not taken.
✗ Branch 772 not taken.
✗ Branch 773 not taken.
✗ Branch 774 not taken.
✗ Branch 775 not taken.
✗ Branch 776 not taken.
✗ Branch 777 not taken.
✗ Branch 778 not taken.
✗ Branch 779 not taken.
✗ Branch 780 not taken.
✗ Branch 781 not taken.
✗ Branch 782 not taken.
✗ Branch 783 not taken.
✗ Branch 784 not taken.
✗ Branch 785 not taken.
✗ Branch 786 not taken.
✗ Branch 787 not taken.
✗ Branch 788 not taken.
✗ Branch 789 not taken.
✗ Branch 790 not taken.
✗ Branch 791 not taken.
✗ Branch 792 not taken.
✗ Branch 793 not taken.
✗ Branch 794 not taken.
✗ Branch 795 not taken.
✗ Branch 796 not taken.
✗ Branch 797 not taken.
✗ Branch 798 not taken.
✓ Branch 799 taken 10 times.
✓ Branch 800 taken 46 times.
✗ Branch 801 not taken.
✗ Branch 802 not taken.
✗ Branch 803 not taken.
✗ Branch 804 not taken.
✗ Branch 805 not taken.
✗ Branch 806 not taken.
✗ Branch 807 not taken.
✗ Branch 808 not taken.
✗ Branch 809 not taken.
✗ Branch 810 not taken.
✗ Branch 811 not taken.
✗ Branch 812 not taken.
✗ Branch 813 not taken.
✗ Branch 814 not taken.
✗ Branch 815 not taken.
✓ Branch 816 taken 1 times.
✗ Branch 817 not taken.
✗ Branch 818 not taken.
✓ Branch 819 taken 1 times.
✓ Branch 820 taken 1 times.
✗ Branch 821 not taken.
✗ Branch 822 not taken.
✓ Branch 823 taken 279 times.
✗ Branch 824 not taken.
✗ Branch 825 not taken.
✗ Branch 826 not taken.
✗ Branch 827 not taken.
✗ Branch 828 not taken.
✗ Branch 829 not taken.
✗ Branch 830 not taken.
✗ Branch 831 not taken.
✗ Branch 832 not taken.
✗ Branch 833 not taken.
✗ Branch 834 not taken.
✗ Branch 835 not taken.
✗ Branch 836 not taken.
✗ Branch 837 not taken.
✗ Branch 838 not taken.
✗ Branch 839 not taken.
✗ Branch 840 not taken.
✗ Branch 841 not taken.
✗ Branch 842 not taken.
✗ Branch 843 not taken.
✗ Branch 844 not taken.
✗ Branch 845 not taken.
✗ Branch 846 not taken.
✗ Branch 847 not taken.
✓ Branch 848 taken 1338 times.
✓ Branch 849 taken 448056 times.
✗ Branch 850 not taken.
✗ Branch 851 not taken.
✗ Branch 852 not taken.
✗ Branch 853 not taken.
✓ Branch 854 taken 8 times.
✓ Branch 855 taken 137111 times.
✓ Branch 856 taken 10 times.
✗ Branch 857 not taken.
✗ Branch 858 not taken.
✓ Branch 859 taken 14870 times.
✓ Branch 860 taken 17877 times.
✗ Branch 861 not taken.
✗ Branch 862 not taken.
✗ Branch 863 not taken.
✗ Branch 864 not taken.
✗ Branch 865 not taken.
✗ Branch 866 not taken.
✓ Branch 867 taken 76234 times.
✗ Branch 868 not taken.
✗ Branch 869 not taken.
✓ Branch 870 taken 30108 times.
✗ Branch 871 not taken.
✓ Branch 872 taken 67629 times.
✓ Branch 873 taken 1374 times.
✓ Branch 874 taken 30108 times.
✗ Branch 875 not taken.
✓ Branch 876 taken 226 times.
✓ Branch 877 taken 1535 times.
✓ Branch 878 taken 4 times.
✓ Branch 879 taken 22 times.
1148294680 switch(scommand)
24799 {
24800 //always first
24801 case 0xFFFF: //invalid command
24802 {
24803 const char* type_str = ScriptTypeToString(type);
24804 switch(type)
24805 {
24806 case ScriptType::FFC:
24807 zprint("%s Script %s has exited.\n", type_str, ffcmap[i].scriptname.c_str()); break;
24808 case ScriptType::NPC:
24809 zprint("%s Script %s has exited.\n", type_str, npcmap[i].scriptname.c_str()); break;
24810 case ScriptType::Lwpn:
24811 zprint("%s Script %s has exited.\n", type_str, lwpnmap[i].scriptname.c_str()); break;
24812 case ScriptType::Ewpn:
24813 zprint("%s Script %s has exited.\n", type_str, ewpnmap[i].scriptname.c_str()); break;
24814 case ScriptType::ItemSprite:
24815 zprint("%s Script %s has exited.\n", type_str, itemspritemap[i].scriptname.c_str()); break;
24816 case ScriptType::Item:
24817 zprint("%s Script %s has exited.\n", type_str, itemmap[i].scriptname.c_str()); break;
24818 case ScriptType::Global:
24819 zprint("%s Script %s has exited.\n", type_str, globalmap[i].scriptname.c_str()); break;
24820 case ScriptType::Hero:
24821 zprint("%s Script %s has exited.\n", type_str, playermap[i].scriptname.c_str()); break;
24822 case ScriptType::Screen:
24823 zprint("%s Script %s has exited.\n", type_str, screenmap[i].scriptname.c_str()); break;
24824 case ScriptType::OnMap:
24825 case ScriptType::DMap:
24826 case ScriptType::ScriptedActiveSubscreen:
24827 case ScriptType::ScriptedPassiveSubscreen:
24828 zprint("%s Script %s has exited.\n", type_str, dmapmap[i].scriptname.c_str()); break;
24829 case ScriptType::Combo: zprint("%s Script %s has exited.\n", type_str, comboscriptmap[i].scriptname.c_str()); break;
24830
24831 default: break;
24832 }
24833 break;
24834 }
24835 case QUIT:
24836 82664 scommand = 0xFFFF;
24837 82664 break;
24838 case QUIT_NO_DEALLOC:
24839 scommand = 0xFFFF;
24840 no_dealloc = true;
24841 break;
24842
24843 case NOP: //No Operation. Do nothing. -Em
24844 {
24845 // While we are here, skip many NOPs in a row to avoid the overhead
24846 // of the interpreter loop. This is especially good for how `zasm_optimize`
24847 // works, since it replaces many commands with a sequence of NOPs.
24848 // No need to do a bounds check - the last command should always be 0xFFFF.
24849
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12822 times.
12822 if (is_debugging)
24850 break;
24851
2/2
✓ Branch 0 taken 15139 times.
✓ Branch 1 taken 12822 times.
27961 while (zasm[ri->pc + 1].command == NOP)
24852 15139 ri->pc++;
24853 12822 break;
24854 }
24855 case GOTO:
24856 {
24857
1/2
✓ Branch 0 taken 958 times.
✗ Branch 1 not taken.
958 if(sarg1 < 0 )
24858 {
24859 goto_err("GOTO");
24860 scommand = 0xFFFF;
24861 break;
24862 }
24863 958 ri->pc = sarg1;
24864 958 increment = false;
24865 958 break;
24866 }
24867 case GOTOR:
24868 {
24869
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(sarg1 < 0 )
24870 {
24871 goto_err("GOTOR");
24872 scommand = 0xFFFF;
24873 break;
24874 }
24875 8 ri->pc = (get_register(sarg1) / 10000) - 1;
24876 8 increment = false;
24877 }
24878 8 break;
24879
24880 case GOTOTRUE:
24881
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 7 times.
11 if(check_cmp(CMP_EQ))
24882 {
24883
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(sarg1 < 0 )
24884 {
24885 goto_err("GOTOTRUE");
24886 scommand = 0xFFFF;
24887 break;
24888 }
24889 7 ri->pc = sarg1;
24890 7 increment = false;
24891 7 }
24892 11 break;
24893
24894 case GOTOFALSE:
24895 if(check_cmp(CMP_NE))
24896 {
24897 if(sarg1 < 0 )
24898 {
24899 goto_err("GOTOFALSE");
24900 scommand = 0xFFFF;
24901 break;
24902 }
24903 ri->pc = sarg1;
24904 increment = false;
24905 }
24906 break;
24907
24908 case GOTOMORE:
24909
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(check_cmp(CMP_GE))
24910 {
24911
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(sarg1 < 0 )
24912 {
24913 goto_err("GOTOMORE");
24914 scommand = 0xFFFF;
24915 break;
24916 }
24917 2 ri->pc = sarg1;
24918 2 increment = false;
24919 2 }
24920 3 break;
24921
24922 case GOTOLESS:
24923 if(check_cmp(get_qr(qr_GOTOLESSNOTEQUAL) ? CMP_LT : CMP_LE))
24924 {
24925 if(sarg1 < 0 )
24926 {
24927 goto_err("GOTOLESS");
24928 scommand = 0xFFFF;
24929 break;
24930 }
24931 ri->pc = sarg1;
24932 increment = false;
24933 }
24934 break;
24935
24936 case GOTOCMP:
24937 {
24938 1974 bool run = check_cmp(sarg2);
24939
2/2
✓ Branch 0 taken 1177 times.
✓ Branch 1 taken 797 times.
1974 if(run)
24940 {
24941
1/2
✓ Branch 0 taken 797 times.
✗ Branch 1 not taken.
797 if(sarg1 < 0 )
24942 {
24943 goto_err("GOTOCMP");
24944 scommand = 0xFFFF;
24945 break;
24946 }
24947 797 ri->pc = sarg1;
24948 797 increment = false;
24949 797 }
24950 1974 break;
24951 }
24952
24953 case SETCMP:
24954 {
24955 932 bool run = check_cmp(sarg2);
24956
2/2
✓ Branch 0 taken 910 times.
✓ Branch 1 taken 22 times.
932 set_register(sarg1, run ? ((sarg2 & CMP_SETI) ? 10000 : 1) : 0);
24957 932 break;
24958 }
24959
24960 case CALLFUNC:
24961 {
24962 65 retstack_push(ri->pc+1);
24963
1/2
✓ Branch 0 taken 65 times.
✗ Branch 1 not taken.
65 if(sarg1 < 0 )
24964 {
24965 goto_err("CALLFUNC");
24966 scommand = 0xFFFF;
24967 break;
24968 }
24969 65 ri->pc = sarg1;
24970 65 increment = false;
24971 65 break;
24972 }
24973 case RETURNFUNC:
24974 {
24975
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 810 times.
875 if(auto retpc = retstack_pop())
24976 {
24977
1/2
✓ Branch 0 taken 65 times.
✗ Branch 1 not taken.
65 if(*retpc < 0)
24978 {
24979 goto_err("RETURNFUNC");
24980 scommand = 0xFFFF;
24981 break;
24982 }
24983 65 ri->pc = *retpc;
24984 65 increment = false;
24985 65 }
24986 else //Returned from 'void run()', QUIT
24987 {
24988 810 scommand = 0xFFFF;
24989 }
24990 875 break;
24991 }
24992
24993 case LOOP:
24994 {
24995 if(get_register(sarg2) > 0)
24996 {
24997 ri->pc = sarg1;
24998 increment = false;
24999 }
25000 else
25001 {
25002 set_register(sarg1, sarg1 - 1);
25003 }
25004 }
25005 break;
25006
25007 case RETURN:
25008 {
25009 if (script_funcrun)
25010 break; //handled below, poorly. 'RETURNFUNC' does this better now.
25011 ri->pc = SH::read_stack(ri->sp) - 1;
25012 ++ri->sp;
25013 ri->sp &= MASK_SP;
25014 increment = false;
25015 break;
25016 }
25017
25018 case SETTRUE:
25019 4 set_register(sarg1, check_cmp(CMP_EQ) ? 1 : 0);
25020 4 break;
25021
25022 case SETFALSE:
25023 12 set_register(sarg1, check_cmp(CMP_NE) ? 1 : 0);
25024 12 break;
25025
25026 case SETMORE:
25027 4 set_register(sarg1, check_cmp(CMP_GE) ? 1 : 0);
25028 4 break;
25029
25030 case SETLESS:
25031 set_register(sarg1, check_cmp(CMP_LE) ? 1 : 0);
25032 break;
25033
25034 case SETTRUEI:
25035 2 set_register(sarg1, check_cmp(CMP_EQ) ? 10000 : 0);
25036 2 break;
25037
25038 case SETFALSEI:
25039 set_register(sarg1, check_cmp(CMP_NE) ? 10000 : 0);
25040 break;
25041
25042 case SETMOREI:
25043 5 set_register(sarg1, check_cmp(CMP_GE) ? 10000 : 0);
25044 5 break;
25045
25046 case SETLESSI:
25047 set_register(sarg1, check_cmp(CMP_LE) ? 10000 : 0);
25048 break;
25049
25050 case READPODARRAYR:
25051 {
25052 151435890 do_readpod(false);
25053 151435890 break;
25054 }
25055 case READPODARRAYV:
25056 {
25057 81453903 do_readpod(true);
25058 81453903 break;
25059 }
25060 case WRITEPODARRAYRR:
25061 {
25062 50482178 do_writepod(false,false);
25063 50482178 break;
25064 }
25065 case WRITEPODARRAYRV:
25066 {
25067 do_writepod(false,true);
25068 break;
25069 }
25070 case WRITEPODARRAYVR:
25071 {
25072 80746848 do_writepod(true,false);
25073 80746848 break;
25074 }
25075 case WRITEPODARRAYVV:
25076 {
25077 2929235 do_writepod(true,true);
25078 2929235 break;
25079 }
25080 case WRITEPODSTRING:
25081 {
25082 3240415 do_writepodstr();
25083 3240415 break;
25084 }
25085 case WRITEPODARRAY:
25086 {
25087 560049 do_writepodarr();
25088 560049 break;
25089 }
25090
25091 case NOT:
25092 do_not(false);
25093 break;
25094
25095 case COMPAREV:
25096 603 do_comp(true);
25097 603 break;
25098 case COMPAREV2:
25099 do_comp(true,true);
25100 break;
25101
25102 case COMPARER:
25103 1410 do_comp(false);
25104 1410 break;
25105
25106 case STRCMPR:
25107 do_internal_strcmp();
25108 break;
25109
25110 case STRICMPR:
25111 do_internal_stricmp();
25112 break;
25113
25114 case SETV:
25115 2451 do_set(true, type, i);
25116 2451 break;
25117
25118 case SETR:
25119 2833 do_set(false, type, i);
25120 2833 break;
25121
25122 case PUSHR:
25123 4382 do_push(false);
25124 4382 break;
25125
25126 case PUSHV:
25127 1454 do_push(true);
25128 1454 break;
25129
25130 case PEEK:
25131 do_peek();
25132 break;
25133 case PEEKATV:
25134 do_peekat(true);
25135 break;
25136 case STACKWRITEATRV:
25137 do_writeat(false, true);
25138 break;
25139 case STACKWRITEATVV_IF:
25140 if(!check_cmp(sarg3))
25141 break;
25142 [[fallthrough]];
25143 case STACKWRITEATVV:
25144 do_writeat(true, true);
25145 break;
25146 case POP:
25147 5548 do_pop();
25148 5548 break;
25149
25150 case POPARGS:
25151 61 do_pops();
25152 61 break;
25153
25154 case PUSHARGSR:
25155 25 do_pushs(false);
25156 25 break;
25157
25158 case PUSHARGSV:
25159 do_pushs(true);
25160 break;
25161
25162 case LOADI:
25163 50 do_loadi();
25164 50 break;
25165
25166 case STOREI:
25167 8 do_storei();
25168 8 break;
25169
25170 case LOADD:
25171 do_loadd();
25172 break;
25173
25174 case LOAD:
25175 6044 do_load();
25176 6044 break;
25177
25178 case STORED:
25179 do_stored(false);
25180 break;
25181 case STOREDV:
25182 do_stored(true);
25183 break;
25184 case STORE:
25185 2162 do_store(false);
25186 2162 break;
25187 case STOREV:
25188 do_store(true);
25189 break;
25190 case STORE_OBJECT:
25191 do_store_object(false);
25192 break;
25193
25194 // Note: this was never used.
25195 case ALLOCATEGMEMR:
25196 if(type == ScriptType::Global) do_allocatemem(false, false, type, i);
25197
25198 break;
25199
25200 case ALLOCATEGMEMV:
25201
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2313 times.
2313 if(type == ScriptType::Global) do_allocatemem(true, false, type, i);
25202
25203 2313 break;
25204
25205 case ALLOCATEMEMR:
25206 do_allocatemem(false, true, type, i);
25207 break;
25208
25209 case ALLOCATEMEMV:
25210 13768058 do_allocatemem(true, true, type, i);
25211 13768058 break;
25212
25213 case RESIZEARRAYR:
25214 5 do_resize_array();
25215 5 break;
25216 case OWNARRAYR:
25217 do_own_array(get_register(sarg1), type, i);
25218 break;
25219 case DESTROYARRAYR:
25220 do_destroy_array();
25221 break;
25222
25223 // Pre-3.0, the compiler inserted this command for every local array at the end of it scope.
25224 case DEALLOCATEMEMR:
25225 13656676 do_deallocatemem();
25226 13656676 break;
25227
25228 case SAVEGAMESTRUCTS:
25229 10 using_SRAM = 1;
25230 10 FFCore.do_savegamestructs(false,false);
25231 10 using_SRAM = 0;
25232 10 break;
25233 case READGAMESTRUCTS:
25234 using_SRAM = 1;
25235 FFCore.do_loadgamestructs(false,false);
25236 using_SRAM = 0;
25237 break;
25238 case ARRAYSIZE:
25239 303069076 do_arraysize();
25240 303069076 break;
25241
25242 case GETFFCSCRIPT:
25243 10105619 do_getffcscript();
25244 10105619 break;
25245 case GETITEMSCRIPT:
25246 80 do_getitemscript();
25247 80 break;
25248
25249 case LOAD_FFC:
25250 {
25251
1/2
✓ Branch 0 taken 3358320 times.
✗ Branch 1 not taken.
3358320 if (!ZScriptVersion::ffcRefIsSpriteId())
25252 {
25253 set_register(sarg1, get_register(sarg1) - 10000);
25254 break;
25255 }
25256
25257 3358320 int ffc_id = get_register(sarg1) / 10000 - 1;
25258
1/2
✓ Branch 0 taken 3358320 times.
✗ Branch 1 not taken.
3358320 if (auto ffc = ResolveFFCWithID(ffc_id))
25259 3358320 set_register(sarg1, ffc->getUID());
25260 else
25261 set_register(sarg1, 0);
25262 3358320 break;
25263 }
25264
25265 case LOAD_FFC_2:
25266 {
25267 if (!ZScriptVersion::ffcRefIsSpriteId())
25268 {
25269 set_register(sarg1, get_register(sarg2) - 10000);
25270 break;
25271 }
25272
25273 int screen = get_register(sarg1) / 10000;
25274 int index = get_register(sarg2) / 10000;
25275
25276 if (!is_in_current_region(screen))
25277 {
25278 scripting_log_error_with_context("Must use a screen in the current region. got: {}", screen);
25279 break;
25280 }
25281 if (BC::checkMapdataFFC(index) != SH::_NoError)
25282 break;
25283
25284 ffc_id_t ffc_id = get_region_screen_offset(screen)*MAXFFCS + index;
25285 if (auto ffc = ResolveFFCWithID(ffc_id))
25286 set_register(sarg1, ffc->getUID());
25287 else
25288 set_register(sarg1, 0);
25289
25290 break;
25291 }
25292
25293 case CASTBOOLI:
25294 13 do_boolcast(false);
25295 13 break;
25296
25297 case CASTBOOLF:
25298 4 do_boolcast(true);
25299 4 break;
25300
25301 case ADDV:
25302 987 do_add(true);
25303 987 break;
25304
25305 case ADDR:
25306 1714 do_add(false);
25307 1714 break;
25308
25309 case SUBV:
25310 804 do_sub(true);
25311 804 break;
25312 case SUBV2:
25313 6 do_sub(true,true);
25314 6 break;
25315
25316 case SUBR:
25317 432 do_sub(false);
25318 432 break;
25319
25320 case MULTV:
25321 do_mult(true);
25322 break;
25323
25324 case MULTR:
25325 564 do_mult(false);
25326 564 break;
25327
25328 case DIVV:
25329 do_div(true);
25330 break;
25331 case DIVV2:
25332 do_div(true,true);
25333 break;
25334
25335 case DIVR:
25336 7 do_div(false);
25337 7 break;
25338
25339 case MODV:
25340 do_mod(true);
25341 break;
25342 case MODV2:
25343 do_mod(true,true);
25344 break;
25345
25346 case MODR:
25347 415 do_mod(false);
25348 415 break;
25349
25350 case SINV:
25351 do_trig(true, 0);
25352 break;
25353
25354 case SINR:
25355 9550421 do_trig(false, 0);
25356 9550421 break;
25357
25358 case COSV:
25359 do_trig(true, 1);
25360 break;
25361
25362 case COSR:
25363 6483138 do_trig(false, 1);
25364 6483138 break;
25365
25366 case TANV:
25367 do_trig(true, 2);
25368 break;
25369
25370 case TANR:
25371 100 do_trig(false, 2);
25372 100 break;
25373
25374 case DEGTORAD:
25375 1480 do_degtorad();
25376 1480 break;
25377
25378 case RADTODEG:
25379 138537 do_radtodeg();
25380 138537 break;
25381
25382 case STRINGLENGTH:
25383 6050 FFCore.do_strlen(false);
25384 6050 break;
25385
25386 case ARCSINR:
25387 14918 do_asin(false);
25388 14918 break;
25389
25390 case ARCCOSR:
25391 do_acos(false);
25392 break;
25393
25394 case ARCTANR:
25395 5879938 do_arctan();
25396 5879938 break;
25397
25398 //Text ptr functions
25399 case FONTHEIGHTR:
25400 6352 do_fontheight();
25401 6352 break;
25402 case STRINGWIDTHR:
25403 17821 do_strwidth();
25404 17821 break;
25405 case CHARWIDTHR:
25406 37547 do_charwidth();
25407 37547 break;
25408 case MESSAGEWIDTHR:
25409 ri->d[rEXP1] = 10000* do_msgwidth(get_register(sarg1)/10000);
25410 break;
25411 case MESSAGEHEIGHTR:
25412 ri->d[rEXP1] = 10000* do_msgheight(get_register(sarg1)/10000);
25413 break;
25414 //
25415
25416 case COMBO_AT:
25417 {
25418 499288 int32_t x = get_register(sarg1) / 10000;
25419 499288 int32_t y = get_register(sarg2) / 10000;
25420 499288 x = std::clamp(x, 0, world_w - 1);
25421 499288 y = std::clamp(y, 0, world_h - 1);
25422 499288 set_register(sarg1, (int)COMBOPOS_REGION(x, y) * 10000);
25423 499288 break;
25424 }
25425
25426 case COMBO_ADJUST:
25427 {
25428 16 rpos_t rpos = (rpos_t)(get_register(sarg1) / 10000);
25429
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if (!is_valid_rpos(rpos))
25430 {
25431 set_register(sarg1, -1);
25432 break;
25433 }
25434
25435 144 auto [x, y] = COMBOXY_REGION(rpos);
25436 32 x += get_register(sarg2) / 10000;
25437 32 y += get_register(sarg3) / 10000;
25438 32 x = std::clamp(x, 0, world_w - 1);
25439 32 y = std::clamp(y, 0, world_h - 1);
25440 48 set_register(sarg1, (int)COMBOPOS_REGION(x, y) * 10000);
25441 16 break;
25442 }
25443
25444 //String.h functions 2.55 Alpha 23
25445 2541 case STRINGCOMPARE: FFCore.do_strcmp(); break;
25446 case STRINGICOMPARE: FFCore.do_stricmp(); break;
25447 2925 case STRINGCOPY: FFCore.do_strcpy(false,false); break;
25448 2 case ARRAYCOPY: FFCore.do_arraycpy(false,false); break;
25449 case STRINGNCOMPARE: FFCore.do_strncmp(); break;
25450 case STRINGNICOMPARE: FFCore.do_strnicmp(); break;
25451
25452 //More string.h functions, 19th May, 2019
25453 case XLEN: FFCore.do_xlen(false); break;
25454 case XTOI: FFCore.do_xtoi(false); break;
25455 case ILEN: FFCore.do_ilen(false); break;
25456 case ATOI: FFCore.do_atoi(false); break;
25457 case ATOL: FFCore.do_atol(false); break;
25458 case STRCSPN: FFCore.do_strcspn(); break;
25459 case STRSTR: FFCore.do_strstr(); break;
25460 14 case XTOA: FFCore.do_xtoa(); break;
25461 4797 case ITOA: FFCore.do_itoa(); break;
25462 56 case ITOACAT: FFCore.do_itoacat(); break;
25463 935 case STRCAT: FFCore.do_strcat(); break;
25464 case STRSPN: FFCore.do_strspn(); break;
25465 case STRCHR: FFCore.do_strchr(); break;
25466 case STRRCHR: FFCore.do_strrchr(); break;
25467 case XLEN2: FFCore.do_xlen2(); break;
25468 case XTOI2: FFCore.do_xtoi2(); break;
25469 case ILEN2: FFCore.do_ilen2(); break;
25470 case ATOI2: FFCore.do_atoi2(); break;
25471 case REMCHR2: FFCore.do_remchr2(); break;
25472 case UPPERTOLOWER: FFCore.do_UpperToLower(false); break;
25473 1 case LOWERTOUPPER: FFCore.do_LowerToUpper(false); break;
25474 case CONVERTCASE: FFCore.do_ConvertCase(false); break;
25475
25476 case GETNPCSCRIPT: FFCore.do_getnpcscript(); break;
25477 case GETCOMBOSCRIPT: FFCore.do_getcomboscript(); break;
25478 1707 case GETLWEAPONSCRIPT: FFCore.do_getlweaponscript(); break;
25479 1664 case GETEWEAPONSCRIPT: FFCore.do_geteweaponscript(); break;
25480 case GETHEROSCRIPT: FFCore.do_getheroscript(); break;
25481 137111 case GETGENERICSCRIPT: FFCore.do_getgenericscript(); break;
25482 case GETGLOBALSCRIPT: FFCore.do_getglobalscript(); break;
25483 105 case GETDMAPSCRIPT: FFCore.do_getdmapscript(); break;
25484 case GETSCREENSCRIPT: FFCore.do_getscreenscript(); break;
25485 31 case GETSPRITESCRIPT: FFCore.do_getitemspritescript(); break;
25486 case GETUNTYPEDSCRIPT: FFCore.do_getuntypedscript(); break;
25487 case GETSUBSCREENSCRIPT:FFCore.do_getsubscreenscript(); break;
25488 case GETNPCBYNAME: FFCore.do_getnpcbyname(); break;
25489 case GETITEMBYNAME: FFCore.do_getitembyname(); break;
25490 case GETCOMBOBYNAME: FFCore.do_getcombobyname(); break;
25491 case GETDMAPBYNAME: FFCore.do_getdmapbyname(); break;
25492
25493 case ABS:
25494 do_abs(false);
25495 break;
25496
25497 case MINR:
25498 do_min(false);
25499 break;
25500
25501 case MINV:
25502 do_min(true);
25503 break;
25504
25505 case MAXR:
25506 do_max(false);
25507 break;
25508 case MAXV:
25509 do_max(true);
25510 break;
25511 case WRAPRADIANS:
25512 do_wrap_rad(false);
25513 break;
25514 case WRAPDEGREES:
25515 2397 do_wrap_deg(false);
25516 2397 break;
25517
25518 case MAXVARG:
25519 1520226 FFCore.do_varg_max();
25520 1520226 break;
25521 case MINVARG:
25522 140579 FFCore.do_varg_min();
25523 140579 break;
25524 case CHOOSEVARG:
25525 5 FFCore.do_varg_choose();
25526 5 break;
25527 case MAKEVARGARRAY:
25528
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
30 assert(sarg1 >= 0 && sarg1 <= (int)script_object_type::last);
25529 30 FFCore.do_varg_makearray(type, i, (script_object_type)sarg1);
25530 30 break;
25531
25532 case PUSHVARGV:
25533 1649936 do_push_varg(true);
25534 1649936 break;
25535 case PUSHVARGR:
25536 1731263 do_push_varg(false);
25537 1731263 break;
25538 case PUSHVARGSV:
25539 2674 do_push_vargs(true);
25540 2674 break;
25541 case PUSHVARGSR:
25542 do_push_vargs(false);
25543 break;
25544
25545 case RNDR:
25546 2912197 do_rnd(false);
25547 2912197 break;
25548
25549 case RNDV:
25550 do_rnd(true);
25551 break;
25552
25553 case SRNDR:
25554 do_srnd(false);
25555 break;
25556
25557 case SRNDV:
25558 do_srnd(true);
25559 break;
25560
25561 case SRNDRND:
25562 do_srndrnd();
25563 break;
25564
25565 case GETRTCTIMER:
25566 15 FFCore.getRTC(false);
25567 15 break;
25568 case GETRTCTIMEV:
25569 FFCore.getRTC(true);
25570 break;
25571
25572 case FACTORIAL:
25573 do_factorial(false);
25574 break;
25575
25576 case SQROOTV:
25577 do_sqroot(true);
25578 break;
25579
25580 case SQROOTR:
25581 10089782 do_sqroot(false);
25582 10089782 break;
25583
25584 case POWERR:
25585 6556 do_power(false);
25586 6556 break;
25587 case POWERV:
25588 do_power(true);
25589 break;
25590 case POWERV2:
25591 do_power(true,true);
25592 break;
25593
25594 case LPOWERR:
25595 do_lpower(false);
25596 break;
25597 case LPOWERV:
25598 do_lpower(true);
25599 break;
25600 case LPOWERV2:
25601 do_lpower(true,true);
25602 break;
25603
25604 case IPOWERR:
25605 do_ipower(false);
25606 break;
25607
25608 case IPOWERV:
25609 do_ipower(true);
25610 break;
25611
25612 case LOG10:
25613 969 do_log10(false);
25614 969 break;
25615
25616 case LOGE:
25617 648 do_naturallog(false);
25618 648 break;
25619
25620 case ANDR:
25621 1 do_and(false);
25622 1 break;
25623
25624 case ANDV:
25625 do_and(true);
25626 break;
25627
25628 case ORR:
25629 8299299 do_or(false);
25630 8299299 break;
25631
25632 case ORV:
25633 1129056 do_or(true);
25634 1129056 break;
25635
25636 case XORR:
25637 678025 do_xor(false);
25638 678025 break;
25639
25640 case XORV:
25641 243283 do_xor(true);
25642 243283 break;
25643
25644 case NANDR:
25645 do_nand(false);
25646 break;
25647
25648 case NANDV:
25649 do_nand(true);
25650 break;
25651
25652 case NORR:
25653 do_nor(false);
25654 break;
25655
25656 case NORV:
25657 do_nor(true);
25658 break;
25659
25660 case XNORR:
25661 do_xnor(false);
25662 break;
25663
25664 case XNORV:
25665 do_xnor(true);
25666 break;
25667
25668 case BITNOT:
25669 3709786 do_bitwisenot(false);
25670 3709786 break;
25671
25672 case LSHIFTR:
25673 73964923 do_lshift(false);
25674 73964923 break;
25675
25676 case LSHIFTV:
25677 2752222 do_lshift(true);
25678 2752222 break;
25679
25680 case RSHIFTR:
25681 26716589 do_rshift(false);
25682 26716589 break;
25683
25684 case RSHIFTV:
25685 4677945 do_rshift(true);
25686 4677945 break;
25687
25688 case ANDR32:
25689 34306 do_and32(false);
25690 34306 break;
25691
25692 case ANDV32:
25693 10744 do_and32(true);
25694 10744 break;
25695
25696 case ORR32:
25697 17 do_or32(false);
25698 17 break;
25699
25700 case ORV32:
25701 do_or32(true);
25702 break;
25703
25704 case XORR32:
25705 do_xor32(false);
25706 break;
25707
25708 case XORV32:
25709 do_xor32(true);
25710 break;
25711
25712 case BITNOT32:
25713 do_bitwisenot32(false);
25714 break;
25715
25716 case LSHIFTR32:
25717 22 do_lshift32(false);
25718 22 break;
25719
25720 case LSHIFTV32:
25721 do_lshift32(true);
25722 break;
25723
25724 case RSHIFTR32:
25725 34296 do_rshift32(false);
25726 34296 break;
25727
25728 case RSHIFTV32:
25729 do_rshift32(true);
25730 break;
25731
25732 case TRACER:
25733 10283 FFCore.do_trace(false);
25734 10283 break;
25735
25736 case TRACELR:
25737 FFCore.do_tracel(false);
25738 break;
25739
25740 case TRACEV:
25741 34 FFCore.do_trace(true);
25742 34 break;
25743
25744 case TRACE2R:
25745 FFCore.do_tracebool(false);
25746 break;
25747
25748 //Zap and Wavy Effects
25749 case FXWAVYR:
25750 FFCore.do_fx_wavy(false);
25751 break;
25752 case FXZAPR:
25753 FFCore.do_fx_zap(false);
25754 break;
25755 //Zap and Wavy Effects
25756 case FXWAVYV:
25757 FFCore.do_fx_wavy(true);
25758 break;
25759 case FXZAPV:
25760 FFCore.do_fx_zap(true);
25761 break;
25762 case GREYSCALER:
25763 FFCore.do_greyscale(false);
25764 break;
25765 case GREYSCALEV:
25766 FFCore.do_greyscale(true);
25767 break;
25768 case MONOCHROMER:
25769 FFCore.do_monochromatic(false);
25770 break;
25771 case MONOCHROMEV:
25772 FFCore.do_monochromatic(true);
25773 break;
25774
25775 case TRACE2V:
25776 FFCore.do_tracebool(true);
25777 break;
25778
25779 case TRACE3:
25780 12 FFCore.do_tracenl();
25781 12 break;
25782
25783 case TRACE4:
25784 2 FFCore.do_cleartrace();
25785 2 break;
25786
25787 case TRACE5:
25788 3 FFCore.do_tracetobase();
25789 3 break;
25790
25791 case TRACE6:
25792 1373 FFCore.do_tracestring();
25793 1373 break;
25794
25795 case PRINTFV:
25796 287 FFCore.do_printf(true, false);
25797 287 break;
25798 case SPRINTFV:
25799 11645 FFCore.do_sprintf(true, false);
25800 11645 break;
25801
25802 case PRINTFVARG:
25803 33562 FFCore.do_printf(true, true);
25804 33562 break;
25805 case SPRINTFVARG:
25806 319 FFCore.do_sprintf(true, true);
25807 319 break;
25808 case PRINTFA:
25809 FFCore.do_printfarr();
25810 break;
25811 case SPRINTFA:
25812 FFCore.do_sprintfarr();
25813 break;
25814 case ARRAYPUSH:
25815 {
25816 15 auto ptr = SH::read_stack(ri->sp + 2);
25817 15 auto val = SH::read_stack(ri->sp + 1);
25818 15 auto indx = SH::read_stack(ri->sp + 0) / 10000;
25819 15 ArrayManager am(ptr);
25820 15 ri->d[rEXP1] = am.push(val,indx) ? 10000 : 0;
25821 15 break;
25822 }
25823 case ARRAYPOP:
25824 {
25825 3 auto ptr = SH::read_stack(ri->sp + 1);
25826 3 auto indx = SH::read_stack(ri->sp + 0) / 10000;
25827 3 ArrayManager am(ptr);
25828 3 ri->d[rEXP1] = am.pop(indx);
25829 3 break;
25830 }
25831
25832 case BREAKPOINT:
25833 FFCore.do_breakpoint();
25834 break;
25835
25836 case WARP:
25837 do_warp(true);
25838 break;
25839
25840 case WARPR:
25841 107 do_warp(false);
25842 107 break;
25843
25844 case PITWARP:
25845 do_pitwarp(true);
25846 break;
25847
25848 case PITWARPR:
25849 127 do_pitwarp(false);
25850 127 break;
25851
25852 case SELECTAWPNV:
25853 do_selectweapon(true, 1);
25854 break;
25855
25856 case SELECTAWPNR:
25857 5660 do_selectweapon(false, 1);
25858 5660 break;
25859
25860 case SELECTBWPNV:
25861 do_selectweapon(true, 0);
25862 break;
25863
25864 case SELECTBWPNR:
25865 5436 do_selectweapon(false, 0);
25866 5436 break;
25867
25868 case SELECTXWPNR:
25869 do_selectweapon(false, 2);
25870 break;
25871
25872 case SELECTYWPNR:
25873 do_selectweapon(false, 3);
25874 break;
25875
25876 case PLAYSOUNDR:
25877 339164 do_sfx(false);
25878 339164 break;
25879
25880 case PLAYSOUNDV:
25881 do_sfx(true);
25882 break;
25883
25884 case ADJUSTSFXVOLUMER: FFCore.do_adjustsfxvolume(false); break;
25885 case ADJUSTSFXVOLUMEV: FFCore.do_adjustsfxvolume(true); break;
25886 2004 case ADJUSTVOLUMER: FFCore.do_adjustvolume(false); break;
25887 case ADJUSTVOLUMEV: FFCore.do_adjustvolume(true); break;
25888
25889 case PLAYMIDIR:
25890 63829 do_midi(false);
25891 63829 break;
25892
25893 case PLAYMIDIV:
25894 do_midi(true);
25895 break;
25896
25897 case PLAYENHMUSIC:
25898 178 do_enh_music(false);
25899 178 break;
25900
25901 case GETMUSICFILE:
25902 236 do_get_enh_music_filename(false);
25903 236 break;
25904
25905 case GETMUSICTRACK:
25906 140 do_get_enh_music_track(false);
25907 140 break;
25908
25909 case SETDMAPENHMUSIC:
25910 3783 do_set_dmap_enh_music(false);
25911 3783 break;
25912
25913 // Audio->
25914
25915 case ENDSOUNDR:
25916 1 stop_sfx(false);
25917 1 break;
25918
25919 case ENDSOUNDV:
25920 stop_sfx(true);
25921 break;
25922
25923 case PAUSESOUNDR:
25924 pause_sfx(false);
25925 break;
25926
25927 case PAUSESOUNDV:
25928 pause_sfx(true);
25929 break;
25930
25931 case RESUMESOUNDR:
25932 resume_sfx(false);
25933 break;
25934
25935 case RESUMESOUNDV:
25936 resume_sfx(true);
25937 break;
25938
25939
25940
25941 case PAUSESFX:
25942 {
25943 int32_t sound = ri->d[rINDEX]/10000;
25944 pause_sfx(sound);
25945
25946 }
25947 break;
25948
25949 case RESUMESFX:
25950 {
25951 int32_t sound = ri->d[rINDEX]/10000;
25952 resume_sfx(sound);
25953 }
25954 break;
25955
25956 case ADJUSTSFX:
25957 {
25958 do_sfx_ex(false);
25959 }
25960 break;
25961
25962 case PLAYSOUNDEX:
25963 {
25964 14 do_sfx_ex(true);
25965 }
25966 14 break;
25967
25968 case GETSFXCOMPLETION:
25969 {
25970 do_get_sfx_completion();
25971 }
25972 break;
25973
25974 case CONTINUESFX:
25975 {
25976 int32_t sound = ri->d[rINDEX]/10000;
25977 //Backend::sfx->cont_sfx(sound);
25978
25979 //! cont_sfx was not ported to the new back end!!!
25980 // I believe this restarted the loop.
25981 resume_sfx(sound);
25982 //What was the old instruction, again? Did it exist? -Z
25983 //continue_sfx(sound);
25984 }
25985 break;
25986
25987
25988 /*
25989 case STOPITEMSOUND:
25990 void stop_item_sfx(int32_t family)
25991 */
25992
25993 // Note: these have never worked.
25994 case PAUSEMUSIC:
25995 //What was the instruction prior to adding backends?
25996 //! The pauseAll() function pauses sfx, not music, so this instruction is not doing what I intended. -Z
25997 //Check AllOff() -Z
25998 //zcmusic_pause(ZCMUSIC* zcm, int32_t pause); is in zcmusic.h
25999 // midi_paused = true;
26000 //pause_all_sfx();
26001
26002 //Backend::sfx->pauseAll();
26003 break;
26004 case RESUMEMUSIC:
26005 //What was the instruction prior to adding backends?
26006 //Check AllOff() -Z
26007 //resume_all_sfx();
26008 // midi_paused = false;
26009 //Backend::sfx->resumeAll();
26010 break;
26011
26012 case MSGSTRR:
26013 1117 do_message(false);
26014 1117 break;
26015
26016 case MSGSTRV:
26017 do_message(true);
26018 break;
26019
26020 case ITEMNAME:
26021 2768 do_getitemname();
26022 2768 break;
26023
26024 case LOADLWEAPONR:
26025 1452537 do_loadlweapon(false);
26026 1452537 break;
26027
26028 case LOADLWEAPONV:
26029 do_loadlweapon(true);
26030 break;
26031
26032 case LOADEWEAPONR:
26033 4712414 do_loadeweapon(false);
26034 4712414 break;
26035
26036 case LOADEWEAPONV:
26037 do_loadeweapon(true);
26038 break;
26039
26040 case LOADITEMR:
26041 585769 do_loaditem(false);
26042 585769 break;
26043
26044 case LOADITEMV:
26045 do_loaditem(true);
26046 break;
26047
26048 case LOADITEMDATAR:
26049 5620654 do_loaditemdata(false);
26050 5620654 break;
26051
26052 //New Datatypes
26053 case LOADSHOPR:
26054 FFScript::do_loadshopdata(false);
26055 break;
26056 case LOADSHOPV:
26057 FFScript::do_loadshopdata(true);
26058 break;
26059
26060 case LOADINFOSHOPR:
26061 FFScript::do_loadinfoshopdata(false);
26062 break;
26063 case LOADINFOSHOPV:
26064 FFScript::do_loadinfoshopdata(true);
26065 break;
26066 case LOADNPCDATAR:
26067 6365 FFScript::do_loadnpcdata(false);
26068 6365 break;
26069 case LOADNPCDATAV:
26070 FFScript::do_loadnpcdata(true);
26071 break;
26072
26073 case LOADCOMBODATAR:
26074 432438 FFScript::do_loadcombodata(false);
26075 432438 break;
26076 case LOADCOMBODATAV:
26077 FFScript::do_loadcombodata(true);
26078 break;
26079
26080 case LOADTMPSCR:
26081 3209679 FFScript::do_loadmapdata_tempscr(false);
26082 3209679 break;
26083 case LOADTMPSCR2:
26084 FFScript::do_loadmapdata_tempscr2(false);
26085 break;
26086 case REGION_LOAD_TMPSCR_FOR_LAYER_COMBO_POS:
26087 do_loadtmpscrforcombopos(false);
26088 break;
26089 case LOADSCROLLSCR:
26090 177544 FFScript::do_loadmapdata_scrollscr(false);
26091 177544 break;
26092 case LOADSCROLLSCR2:
26093 FFScript::do_loadmapdata_scrollscr2(false);
26094 break;
26095
26096 case LOADSPRITEDATAR:
26097 16 FFScript::do_loadspritedata(false);
26098 16 break;
26099 case LOADSPRITEDATAV:
26100 FFScript::do_loadspritedata(true);
26101 break;
26102
26103 case LOADBITMAPDATAR:
26104 10 FFScript::do_loadbitmapid(false);
26105 10 break;
26106
26107
26108 case LOADBITMAPDATAV:
26109 FFScript::do_loadbitmapid(true);
26110 break;
26111
26112 //functions
26113 case LOADDIRECTORYR:
26114 FFCore.do_loaddirectory(); break;
26115 case CREATEPALDATA:
26116 223 FFCore.do_create_paldata(); break;
26117 case CREATEPALDATACLR:
26118 11 FFCore.do_create_paldata_clr(); break;
26119 case MIXCLR:
26120 FFCore.do_mix_clr(); break;
26121 case CREATERGBHEX:
26122 FFCore.do_create_rgb_hex(); break;
26123 case CREATERGB:
26124 11 FFCore.do_create_rgb(); break;
26125 case CONVERTFROMRGB:
26126 FFCore.do_convert_from_rgb(); break;
26127 case CONVERTTORGB:
26128 FFCore.do_convert_to_rgb(); break;
26129 case PALDATALOADLEVEL:
26130 24 FFCore.do_paldata_load_level(); break;
26131 case PALDATALOADSPRITE:
26132 87 FFCore.do_paldata_load_sprite(); break;
26133 case PALDATALOADMAIN:
26134 92 FFCore.do_paldata_load_main(); break;
26135 case PALDATALOADCYCLE:
26136 FFCore.do_paldata_load_cycle(); break;
26137 case PALDATALOADBITMAP:
26138 FFCore.do_paldata_load_bitmap(); break;
26139 case PALDATAWRITELEVEL:
26140 370 FFCore.do_paldata_write_level(); break;
26141 case PALDATAWRITELEVELCS:
26142 FFCore.do_paldata_write_levelcset(); break;
26143 case PALDATAWRITESPRITE:
26144 31 FFCore.do_paldata_write_sprite(); break;
26145 case PALDATAWRITESPRITECS:
26146 FFCore.do_paldata_write_spritecset(); break;
26147 case PALDATAWRITEMAIN:
26148 1064 FFCore.do_paldata_write_main(); break;
26149 case PALDATAWRITEMAINCS:
26150 130 FFCore.do_paldata_write_maincset(); break;
26151 case PALDATAWRITECYCLE:
26152 FFCore.do_paldata_write_cycle(); break;
26153 case PALDATAWRITECYCLECS:
26154 FFCore.do_paldata_write_cyclecset(); break;
26155 case PALDATAVALIDCLR:
26156 FFCore.do_paldata_colorvalid(); break;
26157 case PALDATACLEARCLR:
26158 FFCore.do_paldata_clearcolor(); break;
26159 case PALDATACLEARCSET:
26160 FFCore.do_paldata_clearcset(); break;
26161 case PALDATAMIX:
26162 450 FFCore.do_paldata_mix(); break;
26163 case PALDATAMIXCS:
26164 4781 FFCore.do_paldata_mixcset(); break;
26165 case PALDATACOPY:
26166 FFCore.do_paldata_copy(); break;
26167 case PALDATACOPYCSET:
26168 112 FFCore.do_paldata_copycset(); break;
26169 case PALDATAFREE:
26170
1/2
✓ Branch 0 taken 234 times.
✗ Branch 1 not taken.
234 if (user_paldata* pd = checkPalData(ri->paldataref, true))
26171 {
26172 234 free_script_object(pd->id);
26173 234 }
26174 234 break;
26175 case PALDATAOWN:
26176 if (user_paldata* pd = checkPalData(ri->paldataref, false))
26177 {
26178 own_script_object(pd, type, i);
26179 }
26180 break;
26181 case LOADRNG: //command
26182 931 FFCore.do_loadrng(); break;
26183
26184 case ITEMGETDISPLAYNAME: //command
26185 53 item_display_name(false); break;
26186 case ITEMSETDISPLAYNAME: //command
26187 item_display_name(true); break;
26188 case ITEMGETSHOWNNAME: //command
26189 item_shown_name(); break;
26190
26191 case DMAPDATAGETNAMER: //command
26192 FFScript::do_getDMapData_dmapname(false); break;
26193 case DMAPDATAGETNAMEV: //command
26194 FFScript::do_getDMapData_dmapname(true); break;
26195
26196 case DMAPDATASETNAMER: //command
26197 FFScript::do_setDMapData_dmapname(false); break;
26198 case DMAPDATASETNAMEV: //command
26199 FFScript::do_setDMapData_dmapname(true); break;
26200
26201
26202
26203 case DMAPDATAGETTITLER: //command
26204 FFScript::do_getDMapData_dmaptitle(false); break;
26205 case DMAPDATAGETTITLEV: //command
26206 FFScript::do_getDMapData_dmaptitle(true); break;
26207 case DMAPDATASETTITLER: //command
26208 FFScript::do_setDMapData_dmaptitle(false); break;
26209 case DMAPDATASETTITLEV: //command
26210 FFScript::do_setDMapData_dmaptitle(true); break;
26211
26212
26213 case DMAPDATAGETINTROR: //command
26214 FFScript::do_getDMapData_dmapintro(false); break;
26215 case DMAPDATAGETINTROV: //command
26216 FFScript::do_getDMapData_dmapintro(true); break;
26217 case DMAPDATANSETITROR: //command
26218 FFScript::do_setDMapData_dmapintro(false); break;
26219 case DMAPDATASETINTROV: //command
26220 FFScript::do_setDMapData_dmapintro(true); break;
26221
26222
26223 case DMAPDATAGETMUSICR: //command, string to load a music file
26224 FFScript::do_getDMapData_music(false); break;
26225 case DMAPDATAGETMUSICV: //command, string to load a music file
26226 FFScript::do_getDMapData_music(true); break;
26227 case DMAPDATASETMUSICR: //command, string to load a music file
26228 FFScript::do_setDMapData_music(false); break;
26229 case DMAPDATASETMUSICV: //command, string to load a music file
26230 FFScript::do_setDMapData_music(true); break;
26231
26232 case LOADMESSAGEDATAR: //COMMAND
26233 24 FFScript::do_loadmessagedata(false);
26234 24 break;
26235 case LOADMESSAGEDATAV: //COMMAND
26236 FFScript::do_loadmessagedata(false);
26237 break;
26238
26239
26240 case MESSAGEDATASETSTRINGR: //command
26241 24 FFScript::do_messagedata_setstring(false);
26242 24 break;
26243 case MESSAGEDATASETSTRINGV: //command
26244 FFScript::do_messagedata_setstring(false);
26245 break;
26246
26247 case MESSAGEDATAGETSTRINGR: //command
26248 FFScript::do_messagedata_getstring(false);
26249 break;
26250 case MESSAGEDATAGETSTRINGV: //command
26251 FFScript::do_messagedata_getstring(false);
26252 break;
26253 case LOADITEMDATAV:
26254 do_loaditemdata(true);
26255 break;
26256
26257 case LOADNPCBYSUID:
26258 12 FFCore.do_loadnpc_by_script_uid(false);
26259 12 break;
26260
26261 case LOADLWEAPONBYSUID:
26262 598 FFCore.do_loadlweapon_by_script_uid(false);
26263 598 break;
26264
26265 case LOADWEAPONCBYSUID:
26266 FFCore.do_loadeweapon_by_script_uid(false);
26267 break;
26268
26269 case LOADNPCR:
26270 27870027 do_loadnpc(false);
26271 27870027 break;
26272
26273 case LOADNPCV:
26274 do_loadnpc(true);
26275 break;
26276
26277 case CREATELWEAPONR:
26278 87669 do_createlweapon(false);
26279 87669 break;
26280
26281 case CREATELWEAPONV:
26282 do_createlweapon(true);
26283 break;
26284
26285 case CREATEEWEAPONR:
26286 209493 do_createeweapon(false);
26287 209493 break;
26288
26289 case CREATEEWEAPONV:
26290 do_createeweapon(true);
26291 break;
26292
26293 case CREATEITEMR:
26294 22444 do_createitem(false);
26295 22444 break;
26296
26297 case CREATEITEMV:
26298 do_createitem(true);
26299 break;
26300
26301 case CREATENPCR:
26302 3530 do_createnpc(false);
26303 3530 break;
26304
26305 case CREATENPCV:
26306 do_createnpc(true);
26307 break;
26308
26309 case ISVALIDARRAY:
26310 587 do_isvalidarray();
26311 587 break;
26312
26313 case ISVALIDITEM:
26314 31487 do_isvaliditem();
26315 31487 break;
26316
26317 case ISVALIDBITMAP:
26318 5 FFCore.do_isvalidbitmap();
26319 5 break;
26320
26321 case ISALLOCATEDBITMAP:
26322 43 FFCore.do_isallocatedbitmap();
26323 43 break;
26324
26325 case ISVALIDNPC:
26326 11754119 do_isvalidnpc();
26327 11754119 break;
26328
26329 case ISVALIDLWPN:
26330 1205956 do_isvalidlwpn();
26331 1205956 break;
26332
26333 case ISVALIDEWPN:
26334 160009 do_isvalidewpn();
26335 160009 break;
26336
26337 case LWPNMAKEANGULAR:
26338 do_lwpnmakeangular();
26339 break;
26340
26341 case EWPNMAKEANGULAR:
26342 do_ewpnmakeangular();
26343 break;
26344
26345 case LWPNMAKEDIRECTIONAL:
26346 do_lwpnmakedirectional();
26347 break;
26348
26349 case EWPNMAKEDIRECTIONAL:
26350 do_ewpnmakedirectional();
26351 break;
26352
26353 case LWPNUSESPRITER:
26354 19653 do_lwpnusesprite(false);
26355 19653 break;
26356
26357 case LWPNUSESPRITEV:
26358 do_lwpnusesprite(true);
26359 break;
26360
26361 case EWPNUSESPRITER:
26362 208946 do_ewpnusesprite(false);
26363 208946 break;
26364
26365 case EWPNUSESPRITEV:
26366 do_ewpnusesprite(true);
26367 break;
26368
26369 case CLEARSPRITESR:
26370 do_clearsprites(false);
26371 break;
26372
26373 case CLEARSPRITESV:
26374 do_clearsprites(true);
26375 break;
26376
26377 case ISSOLID:
26378 21032557 do_issolid();
26379 21032557 break;
26380
26381 case MAPDATAISSOLID:
26382 do_mapdataissolid();
26383 break;
26384
26385 case MAPDATAISSOLIDLYR:
26386 do_mapdataissolid_layer();
26387 break;
26388
26389 case ISSOLIDLAYER:
26390 do_issolid_layer();
26391 break;
26392
26393 case SETSIDEWARP:
26394 257 do_setsidewarp();
26395 257 break;
26396
26397 case SETTILEWARP:
26398 5 do_settilewarp();
26399 5 break;
26400
26401 case GETSIDEWARPDMAP:
26402 354947 do_getsidewarpdmap(false);
26403 354947 break;
26404
26405 case GETSIDEWARPSCR:
26406 3 do_getsidewarpscr(false);
26407 3 break;
26408
26409 case GETSIDEWARPTYPE:
26410 do_getsidewarptype(false);
26411 break;
26412
26413 case GETTILEWARPDMAP:
26414 354994 do_gettilewarpdmap(false);
26415 354994 break;
26416
26417 case GETTILEWARPSCR:
26418 50 do_gettilewarpscr(false);
26419 50 break;
26420
26421 case GETTILEWARPTYPE:
26422 3 do_gettilewarptype(false);
26423 3 break;
26424
26425 case LAYERSCREEN:
26426 13670631 do_layerscreen();
26427 13670631 break;
26428
26429 case LAYERMAP:
26430 18282859 do_layermap();
26431 18282859 break;
26432
26433 case SECRETS:
26434 357 do_triggersecrets(ri->screenref);
26435 357 break;
26436
26437 case REGION_TRIGGER_SECRETS:
26438 {
26439 118 int screen = get_register(sarg1) / 10000;
26440
1/2
✓ Branch 0 taken 118 times.
✗ Branch 1 not taken.
118 if (!is_in_current_region(screen))
26441 {
26442 scripting_log_error_with_context("Must use a screen in the current region. got: {}", screen);
26443 break;
26444 }
26445
26446 118 do_triggersecrets(screen);
26447 118 break;
26448 }
26449
26450 case GRAPHICSGETPIXEL:
26451 FFCore.do_graphics_getpixel();
26452 break;
26453 case GRAPHICSCOUNTCOLOR:
26454 FFCore.do_bmpcollision();
26455 break;
26456
26457 case COMBOTILE:
26458 3062 do_combotile(false);
26459 3062 break;
26460
26461 case DRAWLIGHT_CIRCLE:
26462 {
26463 if (get_qr(qr_SCRIPTS_SCREEN_DRAW_LIGHT_NO_OFFSET))
26464 {
26465 static const int ARGS = 7;
26466 zfix cx = zslongToFix(SH::read_stack(ri->sp + (ARGS-1)));
26467 zfix cy = zslongToFix(SH::read_stack(ri->sp + (ARGS-2)));
26468 int radius = SH::read_stack(ri->sp + (ARGS-3));
26469 int transp_rad = SH::read_stack(ri->sp + (ARGS-4));
26470 int dith_rad = SH::read_stack(ri->sp + (ARGS-5));
26471 int dith_type = SH::read_stack(ri->sp + (ARGS-6));
26472 int dith_arg = SH::read_stack(ri->sp + (ARGS-7));
26473 if(radius >= 0) radius /= 10000;
26474 else radius = game->get_light_rad();
26475 if(!radius) break;
26476 if(transp_rad >= 0) transp_rad /= 10000;
26477 if(dith_rad >= 0) dith_rad /= 10000;
26478 if(dith_type >= 0) dith_type /= 10000;
26479 if(dith_arg >= 0) dith_arg /= 10000;
26480
26481 doDarkroomCircle(cx,cy,radius,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
26482 }
26483 else do_drawing_command(scommand, true);
26484
26485 break;
26486 }
26487 case DRAWLIGHT_SQUARE:
26488 {
26489 if (get_qr(qr_SCRIPTS_SCREEN_DRAW_LIGHT_NO_OFFSET))
26490 {
26491 static const int ARGS = 7;
26492 zfix cx = zslongToFix(SH::read_stack(ri->sp + (ARGS-1)));
26493 zfix cy = zslongToFix(SH::read_stack(ri->sp + (ARGS-2)));
26494 int radius = SH::read_stack(ri->sp + (ARGS-3));
26495 int transp_rad = SH::read_stack(ri->sp + (ARGS-4));
26496 int dith_rad = SH::read_stack(ri->sp + (ARGS-5));
26497 int dith_type = SH::read_stack(ri->sp + (ARGS-6));
26498 int dith_arg = SH::read_stack(ri->sp + (ARGS-7));
26499 if(radius >= 0) radius /= 10000;
26500 else radius = game->get_light_rad();
26501 if(!radius) break;
26502 if(transp_rad >= 0) transp_rad /= 10000;
26503 if(dith_rad >= 0) dith_rad /= 10000;
26504 if(dith_type >= 0) dith_type /= 10000;
26505 if(dith_arg >= 0) dith_arg /= 10000;
26506
26507 doDarkroomSquare(cx,cy,radius,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
26508 }
26509 else do_drawing_command(scommand, true);
26510
26511 break;
26512 }
26513 case DRAWLIGHT_CONE:
26514 {
26515 if (get_qr(qr_SCRIPTS_SCREEN_DRAW_LIGHT_NO_OFFSET))
26516 {
26517 static const int ARGS = 8;
26518 zfix cx = zslongToFix(SH::read_stack(ri->sp + (ARGS-1)));
26519 zfix cy = zslongToFix(SH::read_stack(ri->sp + (ARGS-2)));
26520 int dir = SH::read_stack(ri->sp + (ARGS-3)) / 10000;
26521 int length = SH::read_stack(ri->sp + (ARGS-4));
26522 int transp_rad = SH::read_stack(ri->sp + (ARGS-5));
26523 int dith_rad = SH::read_stack(ri->sp + (ARGS-6));
26524 int dith_type = SH::read_stack(ri->sp + (ARGS-7));
26525 int dith_arg = SH::read_stack(ri->sp + (ARGS-8));
26526 if(length >= 0) length /= 10000;
26527 else length = game->get_light_rad()*2;
26528 if(!length) break;
26529 if(dir < 0) break;
26530 else dir = NORMAL_DIR(dir);
26531 if(transp_rad >= 0) transp_rad /= 10000;
26532 if(dith_rad >= 0) dith_rad /= 10000;
26533 if(dith_type >= 0) dith_type /= 10000;
26534 if(dith_arg >= 0) dith_arg /= 10000;
26535
26536 doDarkroomCone(cx,cy,length,dir,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
26537 }
26538 else do_drawing_command(scommand, true);
26539
26540 break;
26541 }
26542
26543 case RECTR:
26544 case CIRCLER:
26545 case ARCR:
26546 case ELLIPSER:
26547 case LINER:
26548 case PUTPIXELR:
26549 case PIXELARRAYR:
26550 case TILEARRAYR:
26551 case LINESARRAY:
26552 case COMBOARRAYR:
26553 case DRAWTILER:
26554 case DRAWTILECLOAKEDR:
26555 case DRAWCOMBOR:
26556 case DRAWCOMBOCLOAKEDR:
26557 case DRAWCHARR:
26558 case DRAWINTR:
26559 case QUADR:
26560 case TRIANGLER:
26561 case QUAD3DR:
26562 case TRIANGLE3DR:
26563 case FASTTILER:
26564 case FASTCOMBOR:
26565 case DRAWSTRINGR:
26566 case DRAWSTRINGR2:
26567 case BMPDRAWSTRINGR2:
26568 case SPLINER:
26569 case BITMAPR:
26570 case BITMAPEXR:
26571 case DRAWLAYERR:
26572 case DRAWSCREENR:
26573 case POLYGONR:
26574 case FRAMER:
26575 case TILEBLIT:
26576 case COMBOBLIT:
26577 45321202 do_drawing_command(scommand, true);
26578 45321202 break;
26579
26580 case BMPRECTR:
26581 case BMPCIRCLER:
26582 case BMPARCR:
26583 case BMPELLIPSER:
26584 case BMPLINER:
26585 case BMPSPLINER:
26586 case BMPPUTPIXELR:
26587 case BMPDRAWTILER:
26588 case BMPDRAWTILECLOAKEDR:
26589 case BMPDRAWCOMBOR:
26590 case BMPDRAWCOMBOCLOAKEDR:
26591 case BMPFASTTILER:
26592 case BMPFASTCOMBOR:
26593 case BMPDRAWCHARR:
26594 case BMPDRAWINTR:
26595 case BMPDRAWSTRINGR:
26596 case BMPQUADR:
26597 case BMPQUAD3DR:
26598 case BMPTRIANGLER:
26599 case BMPTRIANGLE3DR:
26600 case BMPPOLYGONR:
26601 case BMPDRAWLAYERR:
26602 case BMPDRAWLAYERSOLIDR:
26603 case BMPDRAWLAYERCFLAGR:
26604 case BMPDRAWLAYERCTYPER:
26605 case BMPDRAWLAYERCIFLAGR:
26606 case BMPDRAWLAYERSOLIDITYR:
26607 case BMPDRAWSCREENR:
26608 case BMPDRAWSCREENSOLIDR:
26609 case BMPDRAWSCREENSOLID2R:
26610 case BMPDRAWSCREENCOMBOFR:
26611 case BMPDRAWSCREENCOMBOIR:
26612 case BMPDRAWSCREENCOMBOTR:
26613 case BITMAPGETPIXEL:
26614 case BMPBLIT:
26615 case BMPBLITTO:
26616 case BMPTILEBLIT:
26617 case BMPCOMBOBLIT:
26618 case BMPMODE7:
26619 case WRITEBITMAP:
26620 case CLEARBITMAP:
26621 case BITMAPCLEARTOCOLOR:
26622 case BMPFRAMER:
26623 case BMPWRITETILE:
26624 case BMPDITHER:
26625 case BMPREPLCOLOR:
26626 case BMPSHIFTCOLOR:
26627 case BMPMASKDRAW:
26628 case BMPMASKDRAW2:
26629 case BMPMASKDRAW3:
26630 case BMPMASKBLIT:
26631 case BMPMASKBLIT2:
26632 case BMPMASKBLIT3:
26633 53639074 do_drawing_command(scommand, false);
26634 53639074 break;
26635 case READBITMAP:
26636 {
26637 uint32_t bitref = SH::read_stack(ri->sp+2);
26638 if(user_bitmap* b = checkBitmap(bitref,false,true))
26639 do_drawing_command(scommand, false);
26640 else //If the pointer isn't allocated, attempt to allocate it first
26641 {
26642 bitref = FFCore.get_free_bitmap();
26643 ri->d[rEXP2] = bitref; //Return to ptr
26644 if(bitref) SH::write_stack(ri->sp+2,bitref); //Write the ref, for the drawing command to read
26645 else break; //No ref allocated; don't enqueue the drawing command.
26646 do_drawing_command(scommand, false);
26647 }
26648 break;
26649 }
26650 case REGENERATEBITMAP:
26651 {
26652 26528 ri->d[rEXP2] = SH::read_stack(ri->sp+3);
26653
1/2
✓ Branch 0 taken 26528 times.
✗ Branch 1 not taken.
26528 if(user_bitmap* b = checkBitmap(ri->d[rEXP2],false,true))
26654 26528 do_drawing_command(scommand, false);
26655 else //If the pointer isn't allocated
26656 {
26657 int32_t w = SH::read_stack(ri->sp) / 10000;
26658 int32_t h = SH::read_stack(ri->sp+1) / 10000;
26659 if ( get_qr(qr_OLDCREATEBITMAP_ARGS) )
26660 {
26661 //flip height and width
26662 h = h ^ w;
26663 w = h ^ w;
26664 h = h ^ w;
26665 }
26666
26667 ri->d[rEXP2] = FFCore.create_user_bitmap_ex(h,w); //Return to ptr
26668 }
26669 26528 break;
26670 }
26671
26672 case BITMAPFREE:
26673 {
26674 3512 FFCore.do_deallocate_bitmap();
26675 3512 break;
26676 }
26677
26678 case BITMAPOWN:
26679 {
26680
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 146 times.
146 if(FFCore.isSystemBitref(ri->bitmapref))
26681 break; //Don't attempt to own system bitmaps!
26682
26683
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 146 times.
146 if (auto bitmap = checkBitmap(ri->bitmapref, false))
26684 146 own_script_object(bitmap, type, i);
26685 146 break;
26686 }
26687
26688 case OBJ_OWN_BITMAP:
26689 {
26690 int bmpid = get_register(sarg1);
26691 if(FFCore.isSystemBitref(bmpid))
26692 break; //Don't attempt to own system bitmaps!
26693 user_bitmap* b = checkBitmap(bmpid, false);
26694 if(!b) break;
26695 ScriptType own_type = (ScriptType)sarg2;
26696 int32_t own_i = get_own_i(own_type);
26697 own_script_object(b, own_type, own_i);
26698 break;
26699 }
26700 case OBJ_OWN_PALDATA:
26701 {
26702 int palid = get_register(sarg1);
26703 user_paldata* pd = checkPalData(palid, false);
26704 if(!pd) break;
26705 ScriptType own_type = (ScriptType)sarg2;
26706 int32_t own_i = get_own_i(own_type);
26707 own_script_object(pd, own_type, own_i);
26708 break;
26709 }
26710 case OBJ_OWN_FILE:
26711 {
26712 int fileid = get_register(sarg1);
26713 user_file* f = checkFile(fileid, false);
26714 if(!f) break;
26715 ScriptType own_type = (ScriptType)sarg2;
26716 int32_t own_i = get_own_i(own_type);
26717 own_script_object(f, own_type, own_i);
26718 break;
26719 }
26720 case OBJ_OWN_DIR:
26721 {
26722 int dirid = get_register(sarg1);
26723 user_dir* dr = checkDir(dirid, false);
26724 if(!dr) break;
26725 ScriptType own_type = (ScriptType)sarg2;
26726 int32_t own_i = get_own_i(own_type);
26727 own_script_object(dr, own_type, own_i);
26728 break;
26729 }
26730 case OBJ_OWN_STACK:
26731 {
26732 int stackid = get_register(sarg1);
26733 user_stack* st = checkStack(stackid, false);
26734 if(!st) break;
26735 ScriptType own_type = (ScriptType)sarg2;
26736 int32_t own_i = get_own_i(own_type);
26737 own_script_object(st, own_type, own_i);
26738 break;
26739 }
26740 case OBJ_OWN_RNG:
26741 {
26742 int rngid = get_register(sarg1);
26743 user_rng* r = checkRNG(rngid, false);
26744 if(!r) break;
26745 ScriptType own_type = (ScriptType)sarg2;
26746 int32_t own_i = get_own_i(own_type);
26747 own_script_object(r, own_type, own_i);
26748 break;
26749 }
26750 case OBJ_OWN_ARRAY:
26751 {
26752 int arrid = get_register(sarg1);
26753 ScriptType own_type = (ScriptType)sarg2;
26754 int32_t own_i = get_own_i(own_type);
26755 do_own_array(arrid, own_type, own_i);
26756 break;
26757 }
26758
26759 case COPYTILEVV:
26760 do_copytile(true, true);
26761 break;
26762
26763 case COPYTILEVR:
26764 do_copytile(true, false);
26765 break;
26766
26767 case COPYTILERV:
26768 do_copytile(false, true);
26769 break;
26770
26771 case COPYTILERR:
26772 49233778 do_copytile(false, false);
26773 49233778 break;
26774
26775 case SWAPTILEVV:
26776 do_swaptile(true, true);
26777 break;
26778
26779 case SWAPTILEVR:
26780 do_swaptile(true, false);
26781 break;
26782
26783 case SWAPTILERV:
26784 do_swaptile(false, true);
26785 break;
26786
26787 case SWAPTILERR:
26788 do_swaptile(false, false);
26789 break;
26790
26791 case CLEARTILEV:
26792 do_cleartile(true);
26793 break;
26794
26795 case CLEARTILER:
26796 10 do_cleartile(false);
26797 10 break;
26798
26799 case OVERLAYTILEVV:
26800 do_overlaytile(true, true);
26801 break;
26802
26803 case OVERLAYTILEVR:
26804 do_overlaytile(true, false);
26805 break;
26806
26807 case OVERLAYTILERV:
26808 do_overlaytile(false, true);
26809 break;
26810
26811 case OVERLAYTILERR:
26812 57032 do_overlaytile(false, false);
26813 57032 break;
26814
26815 case FLIPROTTILEVV:
26816 do_fliprotatetile(true, true);
26817 break;
26818
26819 case FLIPROTTILEVR:
26820 do_fliprotatetile(true, false);
26821 break;
26822
26823 case FLIPROTTILERV:
26824 do_fliprotatetile(false, true);
26825 break;
26826
26827 case FLIPROTTILERR:
26828 do_fliprotatetile(false, false);
26829 break;
26830
26831 case GETTILEPIXEL:
26832 do_gettilepixel();
26833 break;
26834
26835 case SETTILEPIXEL:
26836 do_settilepixel();
26837 break;
26838
26839 case SHIFTTILEVV:
26840 do_shifttile(true, true);
26841 break;
26842
26843 case SHIFTTILEVR:
26844 do_shifttile(true, false);
26845 break;
26846
26847 case SHIFTTILERV:
26848 do_shifttile(false, true);
26849 break;
26850
26851 case SHIFTTILERR:
26852 do_shifttile(false, false);
26853 break;
26854
26855 case SETRENDERTARGET:
26856 7069332 do_set_rendertarget(true);
26857 7069332 break;
26858
26859 case GAMEEND:
26860
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if ( using_SRAM )
26861 {
26862 Z_scripterrlog("Cannot End Game while reading or writing to SRAM. Aborting End. /n");
26863 break;
26864 }
26865 4 Quit = qQUIT;
26866 4 skipcont = 1;
26867 4 scommand = 0xFFFF;
26868 4 break;
26869 case GAMEEXIT:
26870 30 Quit = qEXIT;
26871 30 skipcont = 1;
26872 30 scommand = 0xFFFF;
26873 30 break;
26874 case GAMERELOAD:
26875
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if ( using_SRAM )
26876 {
26877 Z_scripterrlog("Cannot Reload Game while reading or writing to SRAM. Aborting Reload. /n");
26878 break;
26879 }
26880 9 Quit = qRELOAD;
26881 9 skipcont = 1;
26882 9 scommand = 0xFFFF;
26883 9 break;
26884 case GAMESETCUSTOMCURSOR:
26885 {
26886 int32_t bmpptr = SH::read_stack(ri->sp + 4);
26887 int fx = SH::read_stack(ri->sp + 3) / 10000;
26888 int fy = SH::read_stack(ri->sp + 2) / 10000;
26889 bool recolor = SH::read_stack(ri->sp + 1)!=0;
26890 bool scale = SH::read_stack(ri->sp + 0)!=0;
26891 if(user_bitmap* b = checkBitmap(bmpptr,true))
26892 {
26893 custom_mouse(b->u_bmp,fx,fy,recolor,scale);
26894 }
26895 break;
26896 }
26897 case CURRENTITEMID:
26898 {
26899 int ity = SH::read_stack(ri->sp + 1) / 10000;
26900 int flags = SH::read_stack(ri->sp + 0) / 10000;
26901 bool checkcost = flags&0x01;
26902 bool checkjinx = flags&0x02;
26903 bool check_bunny = flags&0x04;
26904 ri->d[rEXP1] = current_item_id(ity,checkcost,checkjinx,check_bunny) * 10000;
26905 break;
26906 }
26907
26908 case GAMECONTINUE:
26909
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if ( using_SRAM )
26910 {
26911 Z_scripterrlog("Cannot Continue Game while reading or writing to SRAM. Aborting Continue. /n");
26912 break;
26913 }
26914 2 reset_all_combo_animations();
26915
26916 2 Quit = qCONT;
26917 2 skipcont = 1;
26918 //cont_game();
26919 2 scommand = 0xFFFF;
26920 2 break;
26921
26922 case GAMESAVEQUIT:
26923 if ( using_SRAM )
26924 {
26925 Z_scripterrlog("Cannot Save Game while reading or writing to SRAM. Aborting Save. /n");
26926 break;
26927 }
26928 Quit = qSAVE;
26929 skipcont = 1;
26930 scommand =0xFFFF;
26931 break;
26932
26933 case GAMESAVECONTINUE:
26934 Quit = qSAVECONT;
26935 skipcont = 1;
26936 scommand =0xFFFF;
26937 break;
26938
26939 case SAVE:
26940
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if ( using_SRAM )
26941 {
26942 Z_scripterrlog("Cannot Save Game while reading or writing to SRAM. Aborting Save. /n");
26943 break;
26944 }
26945
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if(scriptCanSave)
26946 {
26947 30 save_game(false);
26948 30 scriptCanSave=false;
26949 30 }
26950 30 break;
26951
26952 case SAVESCREEN:
26953 do_showsavescreen();
26954 break;
26955
26956 case SHOWF6SCREEN:
26957 onTryQuit();
26958 break;
26959
26960 case SAVEQUITSCREEN:
26961 save_game(false, 1);
26962 break;
26963
26964 //Not Implemented
26965 case ELLIPSE2:
26966 case FLOODFILL:
26967 break;
26968
26969 case ENQUEUER:
26970 do_enqueue(false);
26971 break;
26972
26973 case ENQUEUEV:
26974 do_enqueue(true);
26975 break;
26976
26977 case DEQUEUE:
26978 do_dequeue(false);
26979 break;
26980
26981 //Visual Effects
26982 case WAVYIN:
26983 FFScript::do_wavyin();
26984 break;
26985 case WAVYOUT:
26986 FFScript::do_wavyout();
26987 break;
26988 case ZAPIN:
26989 FFScript::do_zapin();
26990 break;
26991 case ZAPOUT:
26992 FFScript::do_zapout();
26993 break;
26994 case OPENWIPE:
26995 {
26996 FFScript::do_openscreen();
26997 break;
26998 }
26999 case CLOSEWIPE:
27000 {
27001 FFScript::do_closescreen();
27002 break;
27003 }
27004 case OPENWIPESHAPE:
27005 {
27006 FFScript::do_openscreenshape();
27007 break;
27008 }
27009 case CLOSEWIPESHAPE:
27010 {
27011 FFScript::do_closescreenshape();
27012 break;
27013 }
27014
27015 case TINT:
27016 {
27017 3560 FFCore.Tint();
27018 3560 break;
27019 }
27020
27021 case CLEARTINT:
27022 {
27023 66 FFCore.clearTint();
27024 66 break;
27025 }
27026
27027 case MONOHUE:
27028 {
27029 FFCore.gfxmonohue();
27030 break;
27031 }
27032
27033 case SCREENDOSPAWN:
27034 {
27035 ri->d[rEXP1] = scriptloadenemies(ri->screenref) ? 10000 : 0;
27036 break;
27037 }
27038
27039 case SCRTRIGGERCOMBO:
27040 {
27041 int32_t lyr = get_register(sarg1) / 10000;
27042 int32_t pos = get_register(sarg2) / 10000;
27043 rpos_t rpos = (rpos_t)pos;
27044 if (BC::checkComboRpos(rpos) != SH::_NoError)
27045 {
27046 break;
27047 }
27048
27049 set_register(sarg1, do_trigger_combo(get_rpos_handle(rpos, lyr), 0) ? 10000 : 0);
27050 break;
27051 }
27052 case SCRTRIGGERCOMBO2:
27053 {
27054 int32_t lyr = get_register(sarg1) / 10000;
27055 int32_t pos = get_register(sarg2) / 10000;
27056 int32_t idx = get_register(sarg3) / 10000;
27057 rpos_t rpos = (rpos_t)pos;
27058 if (BC::checkComboRpos(rpos) != SH::_NoError)
27059 break;
27060
27061 set_register(sarg1, do_trigger_combo(get_rpos_handle(rpos, lyr), idx) ? 10000 : 0);
27062 break;
27063 }
27064
27065 case SWITCHNPC:
27066 {
27067 byte effect = vbound(get_register(sarg1)/10000, 0, 255);
27068 set_register(sarg1,0);
27069 if(Hero.switchhookclk) break; //Already switching!
27070 if(GuyH::loadNPC(ri->guyref) == SH::_NoError)
27071 {
27072 switching_object = guys.getByUID(ri->guyref);
27073 hooked_comborpos = rpos_t::None;
27074 hooked_layerbits = 0;
27075 switching_object->switch_hooked = true;
27076 Hero.doSwitchHook(effect);
27077 set_register(sarg1,10000);
27078 }
27079 break;
27080 }
27081
27082 case SWITCHITM:
27083 {
27084 byte effect = vbound(get_register(sarg1)/10000, 0, 255);
27085 set_register(sarg1,0);
27086 if(Hero.switchhookclk) break; //Already switching!
27087 if(ItemH::loadItem(ri->itemref) == SH::_NoError)
27088 {
27089 switching_object = ItemH::getItem();
27090 hooked_comborpos = rpos_t::None;
27091 hooked_layerbits = 0;
27092 switching_object->switch_hooked = true;
27093 Hero.doSwitchHook(effect);
27094 set_register(sarg1,10000);
27095 }
27096 break;
27097 }
27098
27099 case SWITCHLW:
27100 {
27101 byte effect = vbound(get_register(sarg1)/10000, 0, 255);
27102 set_register(sarg1,0);
27103 if(Hero.switchhookclk) break; //Already switching!
27104 if(LwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
27105 {
27106 switching_object = LwpnH::getWeapon();
27107 hooked_comborpos = rpos_t::None;
27108 hooked_layerbits = 0;
27109 switching_object->switch_hooked = true;
27110 Hero.doSwitchHook(effect);
27111 set_register(sarg1,10000);
27112 }
27113 break;
27114 }
27115
27116 case SWITCHEW:
27117 {
27118 byte effect = vbound(get_register(sarg1)/10000, 0, 255);
27119 set_register(sarg1,0);
27120 if(Hero.switchhookclk) break; //Already switching!
27121 if(EwpnH::loadWeapon(ri->ewpn) == SH::_NoError)
27122 {
27123 switching_object = EwpnH::getWeapon();
27124 hooked_comborpos = rpos_t::None;
27125 hooked_layerbits = 0;
27126 switching_object->switch_hooked = true;
27127 Hero.doSwitchHook(effect);
27128 set_register(sarg1,10000);
27129 }
27130 break;
27131 }
27132
27133 case SWITCHCMB:
27134 {
27135 rpos_t rpos = (rpos_t)(get_register(sarg1)/10000);
27136 set_register(sarg1,0);
27137 if(Hero.switchhookclk) break; //Already switching!
27138 if (!is_valid_rpos(rpos))
27139 break;
27140 switching_object = NULL;
27141 hooked_comborpos = rpos;
27142 hooked_layerbits = 0;
27143 Hero.doSwitchHook(get_register(sarg2)/10000);
27144 if(!hooked_layerbits) //failed
27145 Hero.reset_hookshot();
27146 else set_register(sarg1,10000); //success return
27147 break;
27148 }
27149
27150 case LINKWARPEXR:
27151 {
27152 92 FFCore.do_warp_ex(false);
27153 92 break;
27154 }
27155
27156 case KILLPLAYER:
27157 {
27158 Hero.kill(get_register(sarg1));
27159 break;
27160 }
27161
27162 case HEROMOVEXY:
27163 {
27164 1798 zfix dx = zslongToFix(SH::read_stack(ri->sp + 4));
27165 1798 zfix dy = zslongToFix(SH::read_stack(ri->sp + 3));
27166 1798 bool kb = SH::read_stack(ri->sp + 2)!=0;
27167 1798 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
27168 1798 bool shove = SH::read_stack(ri->sp + 0)!=0;
27169 1798 ri->d[rEXP1] = Hero.movexy(dx, dy, kb, ign_sv, shove) ? 10000 : 0;
27170 1798 break;
27171 }
27172 case HEROCANMOVEXY:
27173 {
27174 3596 zfix dx = zslongToFix(SH::read_stack(ri->sp + 4));
27175 3596 zfix dy = zslongToFix(SH::read_stack(ri->sp + 3));
27176 3596 bool kb = SH::read_stack(ri->sp + 2)!=0;
27177 3596 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
27178 3596 bool shove = SH::read_stack(ri->sp + 0)!=0;
27179 3596 ri->d[rEXP1] = Hero.can_movexy(dx, dy, kb, ign_sv, shove) ? 10000 : 0;
27180 3596 break;
27181 }
27182 case HEROMOVEATANGLE:
27183 {
27184 zfix degrees = zslongToFix(SH::read_stack(ri->sp + 4));
27185 zfix pxamnt = zslongToFix(SH::read_stack(ri->sp + 3));
27186 bool kb = SH::read_stack(ri->sp + 2)!=0;
27187 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
27188 bool shove = SH::read_stack(ri->sp + 0)!=0;
27189 ri->d[rEXP1] = Hero.moveAtAngle(degrees, pxamnt, kb, ign_sv, shove) ? 10000 : 0;
27190 break;
27191 }
27192 case HEROCANMOVEATANGLE:
27193 {
27194 zfix degrees = zslongToFix(SH::read_stack(ri->sp + 4));
27195 zfix pxamnt = zslongToFix(SH::read_stack(ri->sp + 3));
27196 bool kb = SH::read_stack(ri->sp + 2)!=0;
27197 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
27198 bool shove = SH::read_stack(ri->sp + 0)!=0;
27199 ri->d[rEXP1] = Hero.can_moveAtAngle(degrees, pxamnt, kb, ign_sv, shove) ? 10000 : 0;
27200 break;
27201 }
27202 case HEROMOVE:
27203 {
27204 int dir = SH::read_stack(ri->sp + 4)/10000;
27205 zfix pxamnt = zslongToFix(SH::read_stack(ri->sp + 3));
27206 bool kb = SH::read_stack(ri->sp + 2)!=0;
27207 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
27208 bool shove = SH::read_stack(ri->sp + 0)!=0;
27209 ri->d[rEXP1] = Hero.moveDir(dir, pxamnt, kb, ign_sv, shove) ? 10000 : 0;
27210 break;
27211 }
27212 case HEROCANMOVE:
27213 {
27214 440764 int dir = SH::read_stack(ri->sp + 4)/10000;
27215 440764 zfix pxamnt = zslongToFix(SH::read_stack(ri->sp + 3));
27216 440764 bool kb = SH::read_stack(ri->sp + 2)!=0;
27217 440764 bool ign_sv = SH::read_stack(ri->sp + 1)!=0;
27218 440764 bool shove = SH::read_stack(ri->sp + 0)!=0;
27219 440764 ri->d[rEXP1] = Hero.can_moveDir(dir, pxamnt, kb, ign_sv, shove) ? 10000 : 0;
27220 440764 break;
27221 }
27222 case HEROLIFTRELEASE:
27223 {
27224 if(Hero.lift_wpn)
27225 {
27226 ri->d[rEXP1] = Hero.lift_wpn->getUID();
27227 Lwpns.add(Hero.lift_wpn);
27228 Hero.lift_wpn = nullptr;
27229 }
27230 else ri->d[rEXP1] = 0;
27231 break;
27232 }
27233 case HEROLIFTGRAB:
27234 {
27235 auto lwuid = SH::read_stack(ri->sp + 2);
27236 auto lifttime = SH::read_stack(ri->sp + 1)/10000;
27237 auto liftheight = zslongToFix(SH::read_stack(ri->sp + 0));
27238 if(weapon* wpn = checkLWpn(lwuid))
27239 {
27240 Hero.lift(wpn, lifttime, liftheight);
27241 if(Lwpns.find(wpn) > -1)
27242 Lwpns.remove(wpn);
27243 if(type == ScriptType::Lwpn && lwuid == i)
27244 earlyretval = RUNSCRIPT_SELFREMOVE;
27245 }
27246 break;
27247 }
27248 case HEROISFLICKERFRAME:
27249 ri->d[rEXP1] = Hero.is_hitflickerframe() ? 10000 : 0;
27250 break;
27251 case LOADPORTAL:
27252 {
27253 auto val = get_register(sarg1)/10000;
27254 if(val != -1)
27255 {
27256 portal* prt = (portal*)portals.spr(val);
27257 if(prt)
27258 val = prt->getUID();
27259 else
27260 {
27261 Z_scripterrlog("Tried to load invalid portal index '%d'\n", val);
27262 val = 0;
27263 }
27264 }
27265 ri->portalref = ri->d[rEXP1] = val;
27266 break;
27267 }
27268 case CREATEPORTAL:
27269 {
27270 portal* p = new portal();
27271 if(portals.add(p))
27272 ri->portalref = ri->d[rEXP1] = p->getUID();
27273 else
27274 {
27275 ri->portalref = ri->d[rEXP1] = 0;
27276 Z_scripterrlog("Unable to create new portal! Limit reached!\n");
27277 }
27278 break;
27279 }
27280 case LOADSAVPORTAL:
27281 {
27282 auto val = get_register(sarg1)/10000;
27283 savedportal* prt = checkSavedPortal(val);
27284 ri->saveportalref = ri->d[rEXP1] = prt ? val : 0;
27285 break;
27286 }
27287 case CREATESAVPORTAL:
27288 {
27289 if(game->user_portals.size() >= MAX_SAVED_PORTALS)
27290 {
27291 ri->saveportalref = ri->d[rEXP1] = 0;
27292 Z_scripterrlog("Cannot create any more Saved Portals! Remove some first!\n");
27293 break;
27294 }
27295 savedportal& ref = game->user_portals.emplace_back();
27296 ri->saveportalref = ri->d[rEXP1] = ref.getUID();
27297 break;
27298 }
27299 case PORTALREMOVE:
27300 {
27301 if(portal* p = checkPortal(ri->portalref, true))
27302 {
27303 if(p == &mirror_portal)
27304 p->clear();
27305 else
27306 {
27307 auto id = portals.find(p);
27308 if(id > -1)
27309 portals.del(id,true);
27310 }
27311 }
27312 break;
27313 }
27314 case PORTALUSESPRITE:
27315 do_portalusesprite();
27316 break;
27317 case SAVEDPORTALREMOVE:
27318 {
27319 if(savedportal* sp = checkSavedPortal(ri->saveportalref, true))
27320 {
27321 if(sp == &(game->saved_mirror_portal))
27322 sp->clear();
27323 else
27324 {
27325 //ensure all pointers to the object are cleared before deleting
27326 portals.forEach([&](sprite& spr)
27327 {
27328 portal* tmp = (portal*)&spr;
27329 if(sp->getUID() == tmp->saved_data)
27330 {
27331 tmp->saved_data = 0;
27332 }
27333 return false;
27334 });
27335 //delete the savedportal object from the vector
27336 for(auto it = game->user_portals.begin();
27337 it != game->user_portals.end();)
27338 {
27339 savedportal& tmp = *it;
27340 if(sp == &tmp)
27341 {
27342 game->user_portals.erase(it);
27343 break;
27344 }
27345 else ++it;
27346 }
27347 }
27348 }
27349 break;
27350 }
27351 case SAVEDPORTALGENERATE:
27352 {
27353 auto retval = 0;
27354 if(savedportal* sp = checkSavedPortal(ri->saveportalref))
27355 {
27356 retval = getPortalFromSaved(sp);
27357 if(!retval)
27358 {
27359 if(portal* p = loadportal(*sp))
27360 if(portals.add(p))
27361 retval = p->getUID();
27362 }
27363 }
27364 ri->d[rEXP1] = retval;
27365 break;
27366 }
27367
27368 case LINKEXPLODER:
27369 {
27370 int32_t mode = get_register(sarg1) / 10000;
27371 if ( (unsigned) mode > 2 )
27372 {
27373 Z_scripterrlog("Invalid mode (%d) passed to Hero->Explode(int32_t mode)\n",mode);
27374 }
27375 else Hero.explode(mode);
27376 break;
27377 }
27378 case NPCEXPLODER:
27379 {
27380 int32_t mode = get_register(sarg1) / 10000;
27381 if ( (unsigned) mode > 2 )
27382 {
27383 Z_scripterrlog("Invalid mode (%d) passed to npc->Explode(int32_t mode)\n",mode);
27384 }
27385 else
27386 {
27387 if(GuyH::loadNPC(ri->guyref) == SH::_NoError)
27388 {
27389 GuyH::getNPC()->explode(mode);
27390 }
27391 }
27392 break;
27393 }
27394
27395 case ITEMEXPLODER:
27396 {
27397
27398 int32_t mode = get_register(sarg1) / 10000;
27399 if ( (unsigned) mode > 2 )
27400 {
27401 Z_scripterrlog("Invalid mode (%d) passed to item->Explode(int32_t mode)\n",mode);
27402 }
27403 else
27404 {
27405 if(ItemH::loadItem(ri->itemref) == SH::_NoError)
27406 {
27407 ItemH::getItem()->explode(mode);
27408 }
27409 }
27410 break;
27411 }
27412 case LWEAPONEXPLODER:
27413 {
27414 int32_t mode = get_register(sarg1) / 10000;
27415 if ( (unsigned) mode > 2 )
27416 {
27417 Z_scripterrlog("Invalid mode (%d) passed to lweapon->Explode(int32_t mode)\n",mode);
27418 }
27419 else
27420 {
27421 if(LwpnH::loadWeapon(ri->lwpn) == SH::_NoError)
27422 {
27423 LwpnH::getWeapon()->explode(mode);
27424 }
27425 }
27426 break;
27427 }
27428 case EWEAPONEXPLODER:
27429 {
27430 int32_t mode = get_register(sarg1) / 10000;
27431 if ( (unsigned) mode > 2 )
27432 {
27433 Z_scripterrlog("Invalid mode (%d) passed to eweapon->Explode(int32_t mode)\n",mode);
27434 }
27435 else
27436 {
27437 if(EwpnH::loadWeapon(ri->ewpn) == SH::_NoError)
27438 {
27439 EwpnH::getWeapon()->explode(mode);
27440 }
27441 }
27442 break;
27443 }
27444
27445 case BOTTLENAMEGET:
27446 {
27447 int32_t arrayptr = get_register(sarg1);
27448 int32_t id = ri->bottletyperef-1;
27449 if(unsigned(id) > 63)
27450 {
27451 Z_scripterrlog("Invalid bottledata ID (%d) passed to bottledata->GetName().\n", id);
27452 break;
27453 }
27454
27455 if(ArrayH::setArray(arrayptr, QMisc.bottle_types[id].name) == SH::_Overflow)
27456 Z_scripterrlog("Array supplied to 'bottledata->GetName()' not large enough\n");
27457 break;
27458 }
27459 case BOTTLENAMESET:
27460 {
27461 int32_t arrayptr = get_register(sarg1);
27462 int32_t id = ri->bottletyperef-1;
27463 if(unsigned(id) > 63)
27464 {
27465 Z_scripterrlog("Invalid bottledata ID (%d) passed to bottledata->SetName().\n", id+1);
27466 break;
27467 }
27468 string name;
27469 ArrayH::getString(arrayptr, name, 31);
27470 strcpy(QMisc.bottle_types[id].name, name.c_str());
27471 break;
27472 }
27473 case BSHOPNAMEGET:
27474 {
27475 int32_t arrayptr = get_register(sarg1);
27476 int32_t id = ri->bottleshopref-1;
27477 if(unsigned(id) > 255)
27478 {
27479 Z_scripterrlog("Invalid bottleshopdata ID (%d) passed to bottleshopdata->GetName().\n", id+1);
27480 break;
27481 }
27482
27483 if(ArrayH::setArray(arrayptr, QMisc.bottle_shop_types[id].name) == SH::_Overflow)
27484 Z_scripterrlog("Array supplied to 'bottleshopdata->GetName()' not large enough\n");
27485 break;
27486 }
27487 case BSHOPNAMESET:
27488 {
27489 int32_t arrayptr = get_register(sarg1);
27490 int32_t id = ri->bottleshopref;
27491 if(unsigned(id) > 255)
27492 {
27493 Z_scripterrlog("Invalid bottleshopdata ID (%d) passed to bottleshopdata->SetName().\n", id);
27494 break;
27495 }
27496 string name;
27497 ArrayH::getString(arrayptr, name, 31);
27498 strcpy(QMisc.bottle_shop_types[id].name, name.c_str());
27499 break;
27500 }
27501
27502 case RUNITEMSCRIPT:
27503 {
27504 15 int32_t itemid = ri->idata;
27505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if(unsigned(itemid) > MAXITEMS) break;
27506 15 int32_t mode = get_register(sarg1) / 10000;
27507 15 auto& data = get_script_engine_data(ScriptType::Item, itemid);
27508
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15 times.
15 switch(mode)
27509 {
27510 case 0:
27511 {
27512 data.doscript = 4;
27513 break;
27514 }
27515 case 1:
27516 {
27517 if ( itemsbuf[itemid].script != 0 ) //&& !data.doscript )
27518 {
27519 if ( !data.doscript )
27520 {
27521 data.ref.Clear();
27522 data.doscript = 1;
27523 //ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[itemid].script, itemid);
27524 }
27525 else
27526 {
27527 //Emily, clear the stack here, clear refinfo, and set up to run again on the next frame from the beginning.
27528 }
27529 }
27530 break;
27531 }
27532 15 case 2:
27533 default:
27534 {
27535
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 if ( itemsbuf[itemid].script != 0 ) //&& !data.doscript )
27536 {
27537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if (data.doscript != 2 )data.doscript = 2;
27538 15 }
27539 15 break;
27540 }
27541 /*
27542 case 0:
27543 {
27544 data.doscript = 0;
27545 break;
27546 }
27547 default:
27548 {
27549
27550 if ( itemsbuf[itemid].script != 0 ) //&& !data.doscript )
27551 {
27552 //itemScriptData[itemid].Clear();
27553 //for ( int32_t q = 0; q < 1024; q++ ) item_stack[itemid][q] = 0;
27554 //ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[itemid].script, itemid & 0xFFF);
27555 data.doscript = 2;
27556 }
27557 break;
27558 }
27559 */
27560 }
27561 15 break;
27562 }
27563
27564 //case NPCData
27565
27566 case GETNPCDATATILE: FFScript::getNPCData_tile(); break;
27567 case GETNPCDATAEHEIGHT: FFScript::getNPCData_e_height(); break;
27568 case GETNPCDATAFLAGS: FFScript::getNPCData_flags(); break;
27569 case GETNPCDATAFLAGS2: FFScript::getNPCData_flags2(); break;
27570 case GETNPCDATAWIDTH: FFScript::getNPCData_width(); break;
27571 case GETNPCDATAHEIGHT: FFScript::getNPCData_height(); break;
27572 case GETNPCDATASTILE: FFScript::getNPCData_s_tile(); break;
27573 case GETNPCDATASWIDTH: FFScript::getNPCData_s_width(); break;
27574 case GETNPCDATASHEIGHT: FFScript::getNPCData_s_height(); break;
27575 case GETNPCDATAETILE: FFScript::getNPCData_e_tile(); break;
27576 case GETNPCDATAEWIDTH: FFScript::getNPCData_e_width(); break;
27577 case GETNPCDATAHP: FFScript::getNPCData_hp(); break;
27578 case GETNPCDATAFAMILY: FFScript::getNPCData_family(); break;
27579 case GETNPCDATACSET: FFScript::getNPCData_cset(); break;
27580 case GETNPCDATAANIM: FFScript::getNPCData_anim(); break;
27581 case GETNPCDATAEANIM: FFScript::getNPCData_e_anim(); break;
27582 case GETNPCDATAFRAMERATE: FFScript::getNPCData_frate(); break;
27583 case GETNPCDATAEFRAMERATE: FFScript::getNPCData_e_frate(); break;
27584 case GETNPCDATATOUCHDMG: FFScript::getNPCData_dp(); break;
27585 case GETNPCDATAWPNDAMAGE: FFScript::getNPCData_wdp(); break;
27586 case GETNPCDATAWEAPON: FFScript::getNPCData_wdp(); break;
27587 case GETNPCDATARANDOM: FFScript::getNPCData_rate(); break;
27588 case GETNPCDATAHALT: FFScript::getNPCData_hrate(); break;
27589 case GETNPCDATASTEP: FFScript::getNPCData_step(); break;
27590 case GETNPCDATAHOMING: FFScript::getNPCData_homing(); break;
27591 case GETNPCDATAHUNGER: FFScript::getNPCData_grumble(); break;
27592 case GETNPCDATADROPSET: FFScript::getNPCData_item_set(); break;
27593 case GETNPCDATABGSFX: FFScript::getNPCData_bgsfx(); break;
27594 case GETNPCDATADEATHSFX: FFScript::getNPCData_deadsfx(); break;
27595 case GETNPCDATAXOFS: FFScript::getNPCData_xofs(); break;
27596 case GETNPCDATAYOFS: FFScript::getNPCData_yofs(); break;
27597 case GETNPCDATAZOFS: FFScript::getNPCData_zofs(); break;
27598 case GETNPCDATAHXOFS: FFScript::getNPCData_hxofs(); break;
27599 case GETNPCDATAHYOFS: FFScript::getNPCData_hyofs(); break;
27600 case GETNPCDATAHITWIDTH: FFScript::getNPCData_hxsz(); break;
27601 case GETNPCDATAHITHEIGHT: FFScript::getNPCData_hysz(); break;
27602 case GETNPCDATAHITZ: FFScript::getNPCData_hzsz(); break;
27603 case GETNPCDATATILEWIDTH: FFScript::getNPCData_txsz(); break;
27604 case GETNPCDATATILEHEIGHT: FFScript::getNPCData_tysz(); break;
27605 case GETNPCDATAWPNSPRITE: FFScript::getNPCData_wpnsprite(); break;
27606 //case GETNPCDATASCRIPTDEF: FFScript::getNPCData_scriptdefence(); break; //2.future cross-compat.
27607 case GETNPCDATADEFENSE: FFScript::getNPCData_defense(); break;
27608 case GETNPCDATASIZEFLAG: FFScript::getNPCData_SIZEflags(); break;
27609 case GETNPCDATAATTRIBUTE: FFScript::getNPCData_misc(); break;
27610 case GETNPCDATAHITSFX: FFScript::getNPCData_hitsfx(); break;
27611
27612 case SETNPCDATAFLAGS: FFScript::setNPCData_flags(); break;
27613 case SETNPCDATAFLAGS2: FFScript::setNPCData_flags2(); break;
27614 case SETNPCDATAWIDTH: FFScript::setNPCData_width(); break;
27615 case SETNPCDATAHEIGHT: FFScript::setNPCData_height(); break;
27616 case SETNPCDATASTILE: FFScript::setNPCData_s_tile(); break;
27617 case SETNPCDATASWIDTH: FFScript::setNPCData_s_width(); break;
27618 case SETNPCDATASHEIGHT: FFScript::setNPCData_s_height(); break;
27619 case SETNPCDATAETILE: FFScript::setNPCData_e_tile(); break;
27620 case SETNPCDATAEWIDTH: FFScript::setNPCData_e_width(); break;
27621 case SETNPCDATAHP: FFScript::setNPCData_hp(); break;
27622 case SETNPCDATAFAMILY: FFScript::setNPCData_family(); break;
27623 case SETNPCDATACSET: FFScript::setNPCData_cset(); break;
27624 case SETNPCDATAANIM: FFScript::setNPCData_anim(); break;
27625 case SETNPCDATAEANIM: FFScript::setNPCData_e_anim(); break;
27626 case SETNPCDATAFRAMERATE: FFScript::setNPCData_frate(); break;
27627 case SETNPCDATAEFRAMERATE: FFScript::setNPCData_e_frate(); break;
27628 case SETNPCDATATOUCHDMG: FFScript::setNPCData_dp(); break;
27629 case SETNPCDATAWPNDAMAGE: FFScript::setNPCData_wdp(); break;
27630 case SETNPCDATAWEAPON: FFScript::setNPCData_weapon(); break;
27631 case SETNPCDATARANDOM: FFScript::setNPCData_rate(); break;
27632 case SETNPCDATAHALT: FFScript::setNPCData_hrate(); break;
27633 case SETNPCDATASTEP: FFScript::setNPCData_step(); break;
27634 case SETNPCDATAHOMING: FFScript::setNPCData_homing(); break;
27635 case SETNPCDATAHUNGER: FFScript::setNPCData_grumble(); break;
27636 case SETNPCDATADROPSET: FFScript::setNPCData_item_set(); break;
27637 case SETNPCDATABGSFX: FFScript::setNPCData_bgsfx(); break;
27638 case SETNPCDATADEATHSFX: FFScript::setNPCData_hitsfx(); break;
27639 case SETNPCDATAXOFS: FFScript::setNPCData_xofs(); break;
27640 case SETNPCDATAYOFS: FFScript::setNPCData_yofs(); break;
27641 case SETNPCDATAZOFS: FFScript::setNPCData_zofs(); break;
27642 case SETNPCDATAHXOFS: FFScript::setNPCData_hxofs(); break;
27643 case SETNPCDATAHYOFS: FFScript::setNPCData_hyofs(); break;
27644 case SETNPCDATAHITWIDTH: FFScript::setNPCData_hxsz(); break;
27645 case SETNPCDATAHITHEIGHT: FFScript::setNPCData_hysz(); break;
27646 case SETNPCDATAHITZ: FFScript::setNPCData_hzsz(); break;
27647 case SETNPCDATATILEWIDTH: FFScript::setNPCData_txsz(); break;
27648 case SETNPCDATATILEHEIGHT: FFScript::setNPCData_tysz(); break;
27649 case SETNPCDATAWPNSPRITE: FFScript::setNPCData_wpnsprite(); break;
27650 case SETNPCDATAHITSFX: FFScript::setNPCData_hitsfx(); break;
27651 case SETNPCDATATILE: FFScript::setNPCData_tile(); break;
27652 case SETNPCDATAEHEIGHT: FFScript::setNPCData_e_height(); break;
27653
27654
27655
27656
27657
27658
27659 //case SETNPCDATASCRIPTDEF : FFScript::setNPCData_scriptdefence(); break;
27660 case SETNPCDATADEFENSE : FFScript::setNPCData_defense(ri->d[rEXP1]); break;
27661 case SETNPCDATASIZEFLAG : FFScript::setNPCData_SIZEflags(ri->d[rEXP1]); break;
27662 case SETNPCDATAATTRIBUTE : FFScript::setNPCData_misc(ri->d[rEXP1]); break;
27663
27664
27665 //ComboData
27666
27667 case GCDBLOCKENEM: FFScript::getComboData_block_enemies(); break;
27668 case GCDBLOCKHOLE: FFScript::getComboData_block_hole(); break;
27669 case GCDBLOCKTRIG: FFScript::getComboData_block_trigger(); break;
27670 case GCDCONVEYSPDX: FFScript::getComboData_conveyor_x_speed(); break;
27671 case GCDCONVEYSPDY: FFScript::getComboData_conveyor_y_speed(); break;
27672 case GCDCREATEENEM: FFScript::getComboData_create_enemy(); break;
27673 case GCDCREATEENEMWH: FFScript::getComboData_create_enemy_when(); break;
27674 case GCDCREATEENEMCH: FFScript::getComboData_create_enemy_change(); break;
27675 case GCDDIRCHTYPE: FFScript::getComboData_directional_change_type(); break;
27676 case GCDDISTCHTILES: FFScript::getComboData_distance_change_tiles(); break;
27677 case GCDDIVEITEM: FFScript::getComboData_dive_item(); break;
27678 case GCDDOCK: FFScript::getComboData_dock(); break;
27679 case GCDFAIRY: FFScript::getComboData_fairy(); break;
27680 case GCDFFCOMBOATTRIB: FFScript::getComboData_ff_combo_attr_change(); break;
27681 case GCDFOOTDECOTILE: FFScript::getComboData_foot_decorations_tile(); break;
27682 case GCDFOOTDECOTYPE: FFScript::getComboData_foot_decorations_type(); break;
27683 case GCDHOOKSHOTGRAB: FFScript::getComboData_hookshot_grab_point(); break;
27684 case GCDLADDERPASS: FFScript::getComboData_ladder_pass(); break;
27685 case GCDLOCKBLOCKTYPE: FFScript::getComboData_lock_block_type(); break;
27686 case GCDLOCKBLOCKCHANGE: FFScript::getComboData_lock_block_change(); break;
27687 case GCDMAGICMIRRORTYPE: FFScript::getComboData_magic_mirror_type(); break;
27688 case GCDMODIFYHPAMOUNT: FFScript::getComboData_modify_hp_amount(); break;
27689 case GCDMODIFYHPDELAY: FFScript::getComboData_modify_hp_delay(); break;
27690 case GCDMODIFYHPTYPE: FFScript::getComboData_modify_hp_type(); break;
27691 case GCDMODIFYMPAMOUNT: FFScript::getComboData_modify_mp_amount(); break;
27692 case GCDMODIFYMPDELAY: FFScript::getComboData_modify_mp_delay(); break;
27693 case GCDMODIFYMPTYPE: FFScript::getComboData_modify_mp_type(); break;
27694 case GCDNOPUSHBLOCKS: FFScript::getComboData_no_push_blocks(); break;
27695 case GCDOVERHEAD: FFScript::getComboData_overhead(); break;
27696 case GCDPLACEENEMY: FFScript::getComboData_place_enemy(); break;
27697 case GCDPUSHDIR: FFScript::getComboData_push_direction(); break;
27698 case GCDPUSHWEIGHT: FFScript::getComboData_push_weight(); break;
27699 case GCDPUSHWAIT: FFScript::getComboData_push_wait(); break;
27700 case GCDPUSHED: FFScript::getComboData_pushed(); break;
27701 case GCDRAFT: FFScript::getComboData_raft(); break;
27702 case GCDRESETROOM: FFScript::getComboData_reset_room(); break;
27703 case GCDSAVEPOINT: FFScript::getComboData_save_point_type(); break;
27704 case GCDSCREENFREEZE: FFScript::getComboData_screen_freeze_type(); break;
27705 case GCDSECRETCOMBO: FFScript::getComboData_secret_combo(); break;
27706 case GCDSINGULAR: FFScript::getComboData_singular(); break;
27707 case GCDSLOWMOVE: FFScript::getComboData_slow_movement(); break;
27708 case GCDSTATUE: FFScript::getComboData_statue_type(); break;
27709 case GCDSTEPTYPE: FFScript::getComboData_step_type(); break;
27710 case GCDSTEPCHANGETO: FFScript::getComboData_step_change_to(); break;
27711 case GCDSTRIKEREMNANTS: FFScript::getComboData_strike_remnants(); break;
27712 case GCDSTRIKEREMNANTSTYPE: FFScript::getComboData_strike_remnants_type(); break;
27713 case GCDSTRIKECHANGE: FFScript::getComboData_strike_change(); break;
27714 case GCDSTRIKECHANGEITEM: FFScript::getComboData_strike_item(); break;
27715 case GCDTOUCHITEM: FFScript::getComboData_touch_item(); break;
27716 case GCDTOUCHSTAIRS: FFScript::getComboData_touch_stairs(); break;
27717 case GCDTRIGGERTYPE: FFScript::getComboData_trigger_type(); break;
27718 case GCDTRIGGERSENS: FFScript::getComboData_trigger_sensitive(); break;
27719 case GCDWARPTYPE: FFScript::getComboData_warp_type(); break;
27720 case GCDWARPSENS: FFScript::getComboData_warp_sensitive(); break;
27721 case GCDWARPDIRECT: FFScript::getComboData_warp_direct(); break;
27722 case GCDWARPLOCATION: FFScript::getComboData_warp_location(); break;
27723 case GCDWATER: FFScript::getComboData_water(); break;
27724 case GCDWHISTLE: FFScript::getComboData_whistle(); break;
27725 case GCDWINGAME: FFScript::getComboData_win_game(); break;
27726 case GCDBLOCKWEAPLVL: FFScript::getComboData_block_weapon_lvl(); break;
27727 case GCDTILE: FFScript::getComboData_tile(); break;
27728 case GCDFLIP: FFScript::getComboData_flip(); break;
27729 case GCDWALK: FFScript::getComboData_walk(); break;
27730 case GCDTYPE: FFScript::getComboData_type(); break;
27731 case GCDCSETS: FFScript::getComboData_csets(); break;
27732 case GCDFOO: break;
27733 case GCDFRAMES: FFScript::getComboData_frames(); break;
27734 case GCDSPEED: FFScript::getComboData_speed(); break;
27735 case GCDNEXTCOMBO: FFScript::getComboData_nextcombo(); break;
27736 case GCDNEXTCSET: FFScript::getComboData_nextcset(); break;
27737 case GCDFLAG: FFScript::getComboData_flag(); break;
27738 case GCDSKIPANIM: FFScript::getComboData_skipanim(); break;
27739 case GCDNEXTTIMER: FFScript::getComboData_nexttimer(); break;
27740 case GCDSKIPANIMY: FFScript::getComboData_skipanimy(); break;
27741 case GCDANIMFLAGS: FFScript::getComboData_animflags(); break;
27742 case GCDBLOCKWEAPON: FFScript::getComboData_block_weapon(); break;
27743 case GCDSTRIKEWEAPONS: FFScript::getComboData_strike_weapons(); break;
27744 case SCDBLOCKENEM: FFScript::setComboData_block_enemies(); break;
27745 case SCDBLOCKHOLE: FFScript::setComboData_block_hole(); break;
27746 case SCDBLOCKTRIG: FFScript::setComboData_block_trigger(); break;
27747 case SCDCONVEYSPDX: FFScript::setComboData_conveyor_x_speed(); break;
27748 case SCDCONVEYSPDY: FFScript::setComboData_conveyor_y_speed(); break;
27749 case SCDCREATEENEM: FFScript::setComboData_create_enemy(); break;
27750 case SCDCREATEENEMWH: FFScript::setComboData_create_enemy_when(); break;
27751 case SCDCREATEENEMCH: FFScript::setComboData_create_enemy_change(); break;
27752 case SCDDIRCHTYPE: FFScript::setComboData_directional_change_type(); break;
27753 case SCDDISTCHTILES: FFScript::setComboData_distance_change_tiles(); break;
27754 case SCDDIVEITEM: FFScript::setComboData_dive_item(); break;
27755 case SCDDOCK: FFScript::setComboData_dock(); break;
27756 case SCDFAIRY: FFScript::setComboData_fairy(); break;
27757 case SCDFFCOMBOATTRIB: FFScript::setComboData_ff_combo_attr_change(); break;
27758 case SCDFOOTDECOTILE: FFScript::setComboData_foot_decorations_tile(); break;
27759 case SCDFOOTDECOTYPE: FFScript::setComboData_foot_decorations_type(); break;
27760 case SCDHOOKSHOTGRAB: FFScript::setComboData_hookshot_grab_point(); break;
27761 case SCDLADDERPASS: FFScript::setComboData_ladder_pass(); break;
27762 case SCDLOCKBLOCKTYPE: FFScript::setComboData_lock_block_type(); break;
27763 case SCDLOCKBLOCKCHANGE: FFScript::setComboData_lock_block_change(); break;
27764 case SCDMAGICMIRRORTYPE: FFScript::setComboData_magic_mirror_type(); break;
27765 case SCDMODIFYHPAMOUNT: FFScript::setComboData_modify_hp_amount(); break;
27766 case SCDMODIFYHPDELAY: FFScript::setComboData_modify_hp_delay(); break;
27767 case SCDMODIFYHPTYPE: FFScript::setComboData_modify_hp_type(); break;
27768 case SCDMODIFYMPAMOUNT: FFScript::setComboData_modify_mp_amount(); break;
27769 case SCDMODIFYMPDELAY: FFScript::setComboData_modify_mp_delay(); break;
27770 case SCDMODIFYMPTYPE: FFScript::setComboData_modify_mp_type(); break;
27771 case SCDNOPUSHBLOCKS: FFScript::setComboData_no_push_blocks(); break;
27772 case SCDOVERHEAD: FFScript::setComboData_overhead(); break;
27773 case SCDPLACEENEMY: FFScript::setComboData_place_enemy(); break;
27774 case SCDPUSHDIR: FFScript::setComboData_push_direction(); break;
27775 case SCDPUSHWEIGHT: FFScript::setComboData_push_weight(); break;
27776 case SCDPUSHWAIT: FFScript::setComboData_push_wait(); break;
27777 case SCDPUSHED: FFScript::setComboData_pushed(); break;
27778 case SCDRAFT: FFScript::setComboData_raft(); break;
27779 case SCDRESETROOM: FFScript::setComboData_reset_room(); break;
27780 case SCDSAVEPOINT: FFScript::setComboData_save_point_type(); break;
27781 case SCDSCREENFREEZE: FFScript::setComboData_screen_freeze_type(); break;
27782 case SCDSECRETCOMBO: FFScript::setComboData_secret_combo(); break;
27783 case SCDSINGULAR: FFScript::setComboData_singular(); break;
27784 case SCDSLOWMOVE: FFScript::setComboData_slow_movement(); break;
27785 case SCDSTATUE: FFScript::setComboData_statue_type(); break;
27786 case SCDSTEPTYPE: FFScript::setComboData_step_type(); break;
27787 case SCDSTEPCHANGETO: FFScript::setComboData_step_change_to(); break;
27788 case SCDSTRIKEREMNANTS: FFScript::setComboData_strike_remnants(); break;
27789 case SCDSTRIKEREMNANTSTYPE: FFScript::setComboData_strike_remnants_type(); break;
27790 case SCDSTRIKECHANGE: FFScript::setComboData_strike_change(); break;
27791 case SCDSTRIKECHANGEITEM: FFScript::setComboData_strike_item(); break;
27792 case SCDTOUCHITEM: FFScript::setComboData_touch_item(); break;
27793 case SCDTOUCHSTAIRS: FFScript::setComboData_touch_stairs(); break;
27794 case SCDTRIGGERTYPE: FFScript::setComboData_trigger_type(); break;
27795 case SCDTRIGGERSENS: FFScript::setComboData_trigger_sensitive(); break;
27796 case SCDWARPTYPE: FFScript::setComboData_warp_type(); break;
27797 case SCDWARPSENS: FFScript::setComboData_warp_sensitive(); break;
27798 case SCDWARPDIRECT: FFScript::setComboData_warp_direct(); break;
27799 case SCDWARPLOCATION: FFScript::setComboData_warp_location(); break;
27800 case SCDWATER: FFScript::setComboData_water(); break;
27801 case SCDWHISTLE: FFScript::setComboData_whistle(); break;
27802 case SCDWINGAME: FFScript::setComboData_win_game(); break;
27803 case SCDBLOCKWEAPLVL: FFScript::setComboData_block_weapon_lvl(); break;
27804 case SCDTILE: FFScript::setComboData_tile(); break;
27805 case SCDFLIP: FFScript::setComboData_flip(); break;
27806 case SCDWALK: FFScript::setComboData_walk(); break;
27807 case SCDTYPE: FFScript::setComboData_type(); break;
27808 case SCDCSETS: FFScript::setComboData_csets(); break;
27809 case SCDFOO: break;
27810 case SCDFRAMES: FFScript::setComboData_frames(); break;
27811 case SCDSPEED: FFScript::setComboData_speed(); break;
27812 case SCDNEXTCOMBO: FFScript::setComboData_nextcombo(); break;
27813 case SCDNEXTCSET: FFScript::setComboData_nextcset(); break;
27814 case SCDFLAG: FFScript::setComboData_flag(); break;
27815 case SCDSKIPANIM: FFScript::setComboData_skipanim(); break;
27816 case SCDNEXTTIMER: FFScript::setComboData_nexttimer(); break;
27817 case SCDSKIPANIMY: FFScript::setComboData_skipanimy(); break;
27818 case SCDANIMFLAGS: FFScript::setComboData_animflags(); break;
27819 case SCDBLOCKWEAPON: FFScript::setComboData_block_weapon(ri->d[rEXP1]); break;
27820 case SCDSTRIKEWEAPONS: FFScript::setComboData_strike_weapons(ri->d[rEXP1]); break;
27821
27822 //SpriteData
27823
27824 //case GETSPRITEDATASTRING:
27825 case GETSPRITEDATATILE: FFScript::getSpriteDataTile(); break;
27826 case GETSPRITEDATAMISC: FFScript::getSpriteDataCSets(); break;
27827 case GETSPRITEDATACGETS: FFScript::getSpriteDataCSets(); break;
27828 case GETSPRITEDATAFRAMES: FFScript::getSpriteDataFrames(); break;
27829 case GETSPRITEDATASPEED: FFScript::getSpriteDataSpeed(); break;
27830 case GETSPRITEDATATYPE: FFScript::getSpriteDataType(); break;
27831
27832 //case SETSPRITEDATASTRING:
27833 case SETSPRITEDATATILE: FFScript::setSpriteDataTile(); break;
27834 case SETSPRITEDATAMISC: FFScript::setSpriteDataMisc(); break;
27835 case SETSPRITEDATACSETS: FFScript::setSpriteDataCSets(); break;
27836 case SETSPRITEDATAFRAMES: FFScript::setSpriteDataFrames(); break;
27837 case SETSPRITEDATASPEED: FFScript::setSpriteDataSpeed(); break;
27838 case SETSPRITEDATATYPE: FFScript::setSpriteDataType(); break;
27839
27840 //Game over Screen
27841 case SETCONTINUESCREEN: FFScript::FFChangeSubscreenText(); break;
27842 case SETCONTINUESTRING: FFScript::FFSetSaveScreenSetting(); break;
27843
27844 case LWPNDEL:
27845 {
27846
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
10 if(type == ScriptType::Lwpn && ri->lwpn == i)
27847 {
27848 8 FFCore.do_lweapon_delete();
27849 8 return RUNSCRIPT_SELFDELETE;
27850 }
27851
27852 2 FFCore.do_lweapon_delete();
27853 2 break;
27854 }
27855 case EWPNDEL:
27856 {
27857
3/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 36 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
46 if(type == ScriptType::Ewpn && ri->ewpn == i)
27858 {
27859 10 FFCore.do_eweapon_delete();
27860 10 return RUNSCRIPT_SELFDELETE;
27861 }
27862
27863 36 FFCore.do_eweapon_delete();
27864 36 break;
27865 }
27866
27867 case PLAYENHMUSICEX:
27868 // DEPRECATED
27869 do_enh_music(false);
27870 break;
27871
27872 case GETENHMUSICPOS:
27873 FFCore.do_get_music_position();
27874 break;
27875
27876 case SETENHMUSICPOS:
27877 FFCore.do_set_music_position(false);
27878 break;
27879
27880 case SETENHMUSICSPEED:
27881 FFCore.do_set_music_speed(false);
27882 break;
27883
27884 case GETENHMUSICLEN:
27885 FFCore.do_get_music_length();
27886 break;
27887
27888 case SETENHMUSICLOOP:
27889 3 FFCore.do_set_music_loop();
27890 3 break;
27891
27892 case ENHCROSSFADE:
27893 5 do_enh_music_crossfade();
27894 5 break;
27895
27896 case DIREXISTS:
27897 FFCore.do_checkdir(true);
27898 break;
27899
27900 case FILEEXISTS:
27901 FFCore.do_checkdir(false);
27902 break;
27903
27904 case FILESYSREMOVE:
27905 FFCore.do_fs_remove();
27906 break;
27907
27908 case TOBYTE:
27909 do_tobyte();
27910 break;
27911 case TOWORD:
27912 do_toword();
27913 break;
27914 case TOSHORT: do_toshort(); break;
27915 case TOSIGNEDBYTE: do_tosignedbyte(); break;
27916 case TOINTEGER: do_tointeger(); break;
27917 case CEILING: do_ceiling(); break;
27918 7 case FLOOR: do_floor(); break;
27919 case TRUNCATE: do_trunc(); break;
27920 case ROUND: do_round(); break;
27921 case ROUNDAWAY: do_roundaway(); break;
27922
27923 case FILECLOSE:
27924 {
27925 FFCore.do_fclose();
27926 break;
27927 }
27928 case FILEFREE:
27929 {
27930 1 FFCore.do_deallocate_file();
27931 1 break;
27932 }
27933 case FILEOWN:
27934 {
27935 1 user_file* f = checkFile(ri->fileref, false);
27936
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(f) own_script_object(f, type, i);
27937 1 break;
27938 }
27939 case FILEISALLOCATED:
27940 {
27941 FFCore.do_file_isallocated();
27942 break;
27943 }
27944 case FILEISVALID:
27945 {
27946 FFCore.do_file_isvalid();
27947 break;
27948 }
27949 case FILEALLOCATE:
27950 {
27951 FFCore.do_allocate_file();
27952 break;
27953 }
27954 case FILEFLUSH:
27955 {
27956 1 FFCore.do_fflush();
27957 1 break;
27958 }
27959 case FILEREMOVE:
27960 {
27961 FFCore.do_fremove();
27962 break;
27963 }
27964 case FILEGETCHAR:
27965 {
27966 FFCore.do_file_getchar();
27967 break;
27968 }
27969 case FILEREWIND:
27970 {
27971 FFCore.do_file_rewind();
27972 break;
27973 }
27974 case FILECLEARERR:
27975 {
27976 FFCore.do_file_clearerr();
27977 break;
27978 }
27979
27980 case FILEOPEN:
27981 {
27982 1 FFCore.do_fopen(false, "rb+");
27983 1 break;
27984 }
27985 case FILECREATE:
27986 {
27987 1 FFCore.do_fopen(false, "wb+");
27988 1 break;
27989 }
27990 case FILEOPENMODE:
27991 {
27992 int32_t arrayptr = get_register(sarg2);
27993 string mode;
27994 ArrayH::getString(arrayptr, mode, 16);
27995 FFCore.do_fopen(false, mode.c_str());
27996 break;
27997 }
27998 case FILEREADSTR:
27999 {
28000 FFCore.do_file_readstring();
28001 break;
28002 }
28003 case FILEWRITESTR:
28004 {
28005 279 FFCore.do_file_writestring();
28006 279 break;
28007 }
28008 case FILEPUTCHAR:
28009 {
28010 FFCore.do_file_putchar();
28011 break;
28012 }
28013 case FILEUNGETCHAR:
28014 {
28015 FFCore.do_file_ungetchar();
28016 break;
28017 }
28018
28019 case FILEREADCHARS:
28020 {
28021 FFCore.do_file_readchars();
28022 break;
28023 }
28024 case FILEREADBYTES:
28025 {
28026 FFCore.do_file_readbytes();
28027 break;
28028 }
28029 case FILEREADINTS:
28030 {
28031 FFCore.do_file_readints();
28032 break;
28033 }
28034 case FILEWRITECHARS:
28035 {
28036 FFCore.do_file_writechars();
28037 break;
28038 }
28039 case FILEWRITEBYTES:
28040 {
28041 FFCore.do_file_writebytes();
28042 break;
28043 }
28044 case FILEWRITEINTS:
28045 {
28046 FFCore.do_file_writeints();
28047 break;
28048 }
28049 case FILESEEK:
28050 {
28051 FFCore.do_file_seek();
28052 break;
28053 }
28054 case FILEGETERROR:
28055 {
28056 FFCore.do_file_geterr();
28057 break;
28058 }
28059 //Directory
28060 case DIRECTORYGET:
28061 {
28062 FFCore.do_directory_get();
28063 break;
28064 }
28065 case DIRECTORYRELOAD:
28066 {
28067 FFCore.do_directory_reload();
28068 break;
28069 }
28070 case DIRECTORYFREE:
28071 {
28072 FFCore.do_directory_free();
28073 break;
28074 }
28075 case DIRECTORYOWN:
28076 {
28077 if(user_dir* dr = checkDir(ri->directoryref))
28078 {
28079 own_script_object(dr, type, i);
28080 }
28081 break;
28082 }
28083 //Stack
28084 case STACKFREE:
28085 {
28086 if(user_stack* st = checkStack(ri->stackref, true))
28087 {
28088 free_script_object(st->id);
28089 }
28090 break;
28091 }
28092 case STACKOWN:
28093 {
28094 if(user_stack* st = checkStack(ri->stackref))
28095 {
28096 own_script_object(st, type, i);
28097 }
28098 break;
28099 }
28100 case STACKCLEAR:
28101 {
28102 if(user_stack* st = checkStack(ri->stackref))
28103 {
28104 st->clearStack();
28105 }
28106 break;
28107 }
28108 case STACKGET:
28109 {
28110 if(user_stack* st = checkStack(ri->stackref, true))
28111 {
28112 int32_t indx = get_register(sarg1); //NOT /10000
28113 set_register(sarg1, st->get(indx)); //NOT *10000
28114 }
28115 else set_register(sarg1, 0L);
28116 break;
28117 }
28118 case STACKSET:
28119 {
28120 if(user_stack* st = checkStack(ri->stackref, true))
28121 {
28122 int32_t indx = get_register(sarg1); //NOT /10000
28123 int32_t val = get_register(sarg2); //NOT /10000
28124 st->set(indx, val); //NOT *10000
28125 }
28126 break;
28127 }
28128 case STACKPOPBACK:
28129 {
28130 if(user_stack* st = checkStack(ri->stackref, true))
28131 {
28132 set_register(sarg1, st->pop_back()); //NOT *10000
28133 }
28134 else set_register(sarg1, 0L);
28135 break;
28136 }
28137 case STACKPOPFRONT:
28138 {
28139 if(user_stack* st = checkStack(ri->stackref, true))
28140 {
28141 set_register(sarg1, st->pop_front()); //NOT *10000
28142 }
28143 else set_register(sarg1, 0L);
28144 break;
28145 }
28146 case STACKPEEKBACK:
28147 {
28148 if(user_stack* st = checkStack(ri->stackref, true))
28149 {
28150 set_register(sarg1, st->peek_back()); //NOT *10000
28151 }
28152 else set_register(sarg1, 0L);
28153 break;
28154 }
28155 case STACKPEEKFRONT:
28156 {
28157 if(user_stack* st = checkStack(ri->stackref, true))
28158 {
28159 set_register(sarg1, st->peek_front()); //NOT *10000
28160 }
28161 else set_register(sarg1, 0L);
28162 break;
28163 }
28164 case STACKPUSHBACK:
28165 {
28166 if(user_stack* st = checkStack(ri->stackref, true))
28167 {
28168 int32_t val = get_register(sarg1); //NOT /10000
28169 st->push_back(val);
28170 }
28171 break;
28172 }
28173 case STACKPUSHFRONT:
28174 {
28175 if(user_stack* st = checkStack(ri->stackref, true))
28176 {
28177 int32_t val = get_register(sarg1); //NOT /10000
28178 st->push_front(val);
28179 }
28180 break;
28181 }
28182
28183 //Module
28184 case MODULEGETIC:
28185 {
28186
28187 int32_t buf_pointer = SH::get_arg(sarg1, false) / 10000;
28188 int32_t element = SH::get_arg(sarg2, false) / 10000;
28189
28190 if ( ((unsigned)element) > 511 )
28191 {
28192 Z_scripterrlog("Illegal itemclass supplied to ZInfo->GetItemClass().\nLegal values are 1 to 511.\n");
28193 }
28194 else
28195 {
28196 char buffer[256] = {0};
28197 strcpy(buffer,ZI.getItemClassName(element));
28198 buffer[255] = '\0';
28199 if(ArrayH::setArray(buf_pointer, buffer) == SH::_Overflow)
28200 {
28201 Z_scripterrlog("Dest string supplied to 'Module->GetItemClass()' is not large enough\n");
28202 }
28203 }
28204
28205 break;
28206 }
28207
28208 //{ Randgen Stuff
28209 case RNGRAND1:
28210 if(user_rng* r = checkRNG(ri->rngref))
28211 {
28212 ri->d[rEXP1] = r->rand(214748, -214748)*10000L;
28213 }
28214 else ri->d[rEXP1] = -10000L;
28215 break;
28216 case RNGRAND2:
28217
1/2
✓ Branch 0 taken 1338 times.
✗ Branch 1 not taken.
1338 if(user_rng* r = checkRNG(ri->rngref))
28218 {
28219 1338 set_register(sarg1,r->rand(get_register(sarg1)/10000L)*10000L);
28220 1338 }
28221 else set_register(sarg1,-10000L);
28222 1338 break;
28223 case RNGRAND3:
28224
1/2
✓ Branch 0 taken 448056 times.
✗ Branch 1 not taken.
448056 if(user_rng* r = checkRNG(ri->rngref))
28225 {
28226 448056 set_register(sarg1,r->rand(get_register(sarg1)/10000L, get_register(sarg2)/10000L)* 10000L);
28227 448056 }
28228 else set_register(sarg1,-10000L);
28229 448056 break;
28230 case RNGLRAND1:
28231 if(user_rng* r = checkRNG(ri->rngref))
28232 {
28233 ri->d[rEXP1] = r->rand();
28234 }
28235 else ri->d[rEXP1] = -10000L;
28236 break;
28237 case RNGLRAND2:
28238 if(user_rng* r = checkRNG(ri->rngref))
28239 {
28240 ri->d[rEXP1] = r->rand(get_register(sarg1));
28241 }
28242 else ri->d[rEXP1] = -10000L;
28243 break;
28244 case RNGLRAND3:
28245 if(user_rng* r = checkRNG(ri->rngref))
28246 {
28247 ri->d[rEXP1] = r->rand(get_register(sarg1), get_register(sarg2));
28248 }
28249 else ri->d[rEXP1] = -10000L;
28250 break;
28251 case RNGSEED:
28252
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73 times.
73 if(user_rng* r = checkRNG(ri->rngref))
28253 {
28254 73 r->srand(get_register(sarg1));
28255 73 }
28256 73 break;
28257 case RNGRSEED:
28258 if(user_rng* r = checkRNG(ri->rngref))
28259 {
28260 ri->d[rEXP1] = r->srand();
28261 }
28262 else ri->d[rEXP1] = -10000;
28263 break;
28264 case RNGFREE:
28265
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(user_rng* r = checkRNG(ri->rngref, true))
28266 {
28267 6 free_script_object(r->id);
28268 6 }
28269 6 break;
28270 case RNGOWN:
28271
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(user_rng* r = checkRNG(ri->rngref, false))
28272 {
28273 8 own_script_object(r, type, i);
28274 8 }
28275 8 break;
28276 //}
28277 case LOADGENERICDATA:
28278 137111 FFCore.do_loadgenericdata(false); break;
28279 case RUNGENFRZSCR:
28280 {
28281 10 bool r = FFCore.runGenericFrozenEngine(word(ri->genericdataref));
28282 10 set_register(sarg1, r ? 10000L : 0L);
28283 10 break;
28284 }
28285
28286 ///----------------------------------------------------------------------------------------------------//
28287
28288 case SUBDATA_GET_NAME:
28289 {
28290 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
28291 {
28292 auto aptr = get_register(sarg1);
28293 if(ArrayH::setArray(aptr, sub->name, true) == SH::_Overflow)
28294 Z_scripterrlog("Array supplied to 'subscreendata->GetName()' not large enough,"
28295 " and couldn't be resized!\n");
28296 }
28297 break;
28298 }
28299 case SUBDATA_SET_NAME:
28300 {
28301 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
28302 {
28303 auto aptr = get_register(sarg1);
28304 ArrayH::getString(aptr, sub->name);
28305 }
28306 break;
28307 }
28308 case SUBDATA_SWAP_PAGES:
28309 {
28310 ri->subdataref = SH::read_stack(ri->sp+2);
28311 if(ZCSubscreen* sub = checkSubData(ri->subdataref))
28312 {
28313 int p1 = SH::read_stack(ri->sp+1) / 10000;
28314 int p2 = SH::read_stack(ri->sp+0) / 10000;
28315 if(unsigned(p1) >= sub->pages.size())
28316 Z_scripterrlog("Invalid page index '%d' passed to subscreendata->SwapPages()\n", p1);
28317 else if(unsigned(p2) >= sub->pages.size())
28318 Z_scripterrlog("Invalid page index '%d' passed to subscreendata->SwapPages()\n", p2);
28319 else sub->swap_pages(p1,p2);
28320 }
28321 break;
28322 }
28323 case SUBPAGE_SWAP_WIDG:
28324 {
28325 ri->subpageref = SH::read_stack(ri->sp+2);
28326 if(SubscrPage* pg = checkSubPage(ri->subpageref))
28327 {
28328 int p1 = SH::read_stack(ri->sp+1) / 10000;
28329 int p2 = SH::read_stack(ri->sp+0) / 10000;
28330 if(unsigned(p1) >= pg->size())
28331 Z_scripterrlog("Invalid page index '%d' passed to subscreenpage->SwapWidgets()\n", p1);
28332 else if(unsigned(p2) >= pg->size())
28333 Z_scripterrlog("Invalid page index '%d' passed to subscreenpage->SwapWidgets()\n", p2);
28334 else pg->swap_widg(p1,p2);
28335 }
28336 break;
28337 }
28338 case SUBPAGE_FIND_WIDGET:
28339 {
28340 14870 ri->d[rEXP1] = 0;
28341 14870 ri->subpageref = SH::read_stack(ri->sp+1);
28342
1/2
✓ Branch 0 taken 14870 times.
✗ Branch 1 not taken.
14870 if(SubscrPage* pg = checkSubPage(ri->subpageref, sstACTIVE))
28343 {
28344 14870 int cursorpos = SH::read_stack(ri->sp+0) / 10000;
28345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14870 times.
14870 if(auto* widg = pg->get_widg_pos(cursorpos,false))
28346 {
28347 14870 auto q = pg->widget_index(widg);
28348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14870 times.
14870 if(q > -1)
28349 {
28350 44610 auto [sub,ty,pgid,_ind] = from_subref(ri->subpageref);
28351 44610 ri->d[rEXP1] = get_subref(sub,ty,pgid,q);
28352 14870 }
28353 14870 }
28354 14870 }
28355 14870 break;
28356 }
28357 case SUBPAGE_FIND_WIDGET_BY_LABEL:
28358 {
28359 17877 ri->d[rEXP1] = 0;
28360 17877 ri->subpageref = SH::read_stack(ri->sp+1);
28361
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17877 times.
17877 if(SubscrPage* pg = checkSubPage(ri->subpageref))
28362 {
28363 17877 int aptr = SH::read_stack(ri->sp+0);
28364 17877 std::string lbl;
28365
1/2
✓ Branch 0 taken 17877 times.
✗ Branch 1 not taken.
17877 ArrayH::getString(aptr, lbl);
28366
1/2
✓ Branch 0 taken 17877 times.
✗ Branch 1 not taken.
17877 if(lbl.size())
28367 {
28368
1/2
✓ Branch 0 taken 17877 times.
✗ Branch 1 not taken.
17877 auto q = pg->find_label_index(lbl);
28369
2/2
✓ Branch 0 taken 12174 times.
✓ Branch 1 taken 5703 times.
17877 if(q > -1)
28370 {
28371 36522 auto [sub,ty,pgid,_ind] = from_subref(ri->subpageref);
28372 36522 ri->d[rEXP1] = get_subref(sub,ty,pgid,q);
28373 12174 }
28374 17877 }
28375 17877 }
28376 17877 break;
28377 }
28378 case SUBPAGE_MOVE_SEL:
28379 {
28380 #define SUBSEL_FLAG_NO_NONEQUIP 0x01
28381 #define SUBSEL_FLAG_NEED_ITEM 0x02
28382 ri->subpageref = SH::read_stack(ri->sp+3);
28383 if(SubscrPage* pg = checkSubPage(ri->subpageref))
28384 {
28385 int flags = SH::read_stack(ri->sp+0) / 10000;
28386 int dir = SH::read_stack(ri->sp+1) / 10000;
28387 int pos = SH::read_stack(ri->sp+2) / 10000;
28388 switch(dir)
28389 {
28390 case up:
28391 dir = SEL_UP;
28392 break;
28393 case down:
28394 dir = SEL_DOWN;
28395 break;
28396 case left:
28397 dir = SEL_LEFT;
28398 break;
28399 case right: default:
28400 dir = SEL_RIGHT;
28401 break;
28402 }
28403
28404 auto newpos = pg->movepos_legacy(dir, (pos<<8)|pg->getIndex(),
28405 255, 255, 255, flags&SUBSEL_FLAG_NO_NONEQUIP,
28406 flags&SUBSEL_FLAG_NEED_ITEM, true) >> 8;
28407 ri->d[rEXP1] = 10000*newpos;
28408 }
28409 break;
28410 }
28411 case SUBPAGE_NEW_WIDG:
28412 {
28413 ri->subpageref = SH::read_stack(ri->sp+1);
28414 if(SubscrPage* pg = checkSubPage(ri->subpageref))
28415 {
28416 if(pg->size() == 0x2000)
28417 break; //Page is full!
28418 int ty = SH::read_stack(ri->sp+0) / 10000;
28419 if(auto* widg = SubscrWidget::newType(ty))
28420 {
28421 widg->posflags = sspUP | sspDOWN | sspSCROLLING;
28422 widg->w = 1;
28423 widg->h = 1;
28424 pg->push_back(widg);
28425 auto [sub,ty,pgid,_ind] = from_subref(ri->subpageref);
28426 ri->d[rEXP1] = get_subref(sub,ty,pgid,pg->size()-1);
28427 }
28428 else Z_scripterrlog("Invalid type %d passed to subscreenpage->CreateWidget()\n",ty);
28429 }
28430 break;
28431 }
28432 case SUBPAGE_DELETE:
28433 {
28434 if(SubscrPage* pg = checkSubPage(ri->subpageref))
28435 {
28436 auto [sub,_ty] = load_subdata(ri->subpageref);
28437 sub->delete_page(pg->getIndex());
28438 }
28439 break;
28440 }
28441 case SUBWIDG_GET_SELTEXT_OVERRIDE:
28442 {
28443 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
28444 {
28445 auto aptr = get_register(sarg1);
28446 if(ArrayH::setArray(aptr, widg->override_text, true) == SH::_Overflow)
28447 Z_scripterrlog("Array supplied to 'subscreenwidget->GetSelTextOverride()' not large enough,"
28448 " and couldn't be resized!\n");
28449 }
28450 break;
28451 }
28452 case SUBWIDG_SET_SELTEXT_OVERRIDE:
28453 {
28454 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
28455 {
28456 auto aptr = get_register(sarg1);
28457 ArrayH::getString(aptr, widg->override_text);
28458 }
28459 break;
28460 }
28461 case SUBWIDG_GET_LABEL:
28462 {
28463
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
28464 {
28465 828 auto aptr = get_register(sarg1);
28466
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(ArrayH::setArray(aptr, widg->label, true) == SH::_Overflow)
28467 Z_scripterrlog("Array supplied to 'subscreenwidget->GetLabel()' not large enough,"
28468 " and couldn't be resized!\n");
28469 828 }
28470 828 break;
28471 }
28472 case SUBWIDG_SET_LABEL:
28473 {
28474 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
28475 {
28476 auto aptr = get_register(sarg1);
28477 ArrayH::getString(aptr, widg->label);
28478 }
28479 break;
28480 }
28481 case SUBWIDG_CHECK_CONDITIONS:
28482 {
28483 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
28484 {
28485 set_register(sarg1, widg->check_conditions() ? 10000 : 0);
28486 }
28487 break;
28488 }
28489 case SUBWIDG_CHECK_VISIBLE:
28490 {
28491 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
28492 {
28493 extern int current_subscr_pos;
28494 set_register(sarg1, widg->visible(current_subscr_pos, game->should_show_time()) ? 10000 : 0);
28495 }
28496 break;
28497 }
28498 case SUBWIDG_TY_GETTEXT:
28499 {
28500 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
28501 {
28502 std::string const* str = nullptr;
28503 byte ty = widg->getType();
28504 switch(ty)
28505 {
28506 case widgTEXT:
28507 str = &((SW_Text*)widg)->text;
28508 break;
28509 case widgTEXTBOX:
28510 str = &((SW_TextBox*)widg)->text;
28511 break;
28512 default:
28513 bad_subwidg_type(true, ty);
28514 break;
28515 }
28516 if(str)
28517 {
28518 auto aptr = get_register(sarg1);
28519 if(ArrayH::setArray(aptr, *str, true) == SH::_Overflow)
28520 Z_scripterrlog("Array supplied to 'subscreenwidget->GetText()' not large enough,"
28521 " and couldn't be resized!\n");
28522 }
28523 }
28524 break;
28525 }
28526 case SUBWIDG_TY_SETTEXT:
28527 {
28528
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76234 times.
76234 if(SubscrWidget* widg = checkSubWidg(ri->subwidgref))
28529 {
28530 76234 std::string* str = nullptr;
28531 76234 byte ty = widg->getType();
28532
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 68852 times.
✓ Branch 2 taken 7382 times.
76234 switch(ty)
28533 {
28534 case widgTEXT:
28535 68852 str = &((SW_Text*)widg)->text;
28536 68852 break;
28537 case widgTEXTBOX:
28538 7382 str = &((SW_TextBox*)widg)->text;
28539 7382 break;
28540 default:
28541 bad_subwidg_type(true, ty);
28542 break;
28543 }
28544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76234 times.
76234 if(str)
28545 {
28546 76234 auto aptr = get_register(sarg1);
28547 76234 ArrayH::getString(aptr, *str);
28548 76234 }
28549 76234 }
28550 76234 break;
28551 }
28552
28553 case COMBOD_GET_TRIGGER:
28554 {
28555 if(ri->combosref < 0 || ri->combosref > (MAXCOMBOS-1) )
28556 {
28557 scripting_log_error_with_context("Invalid combodata ID: {}", ri->combosref);
28558 }
28559 else
28560 {
28561 auto aptr = get_register(sarg1) / 10000;
28562 string name;
28563 ArrayH::getString(aptr, name, 256);
28564 newcombo const& cmb = combobuf[ri->combosref];
28565 int32_t ret = 0;
28566 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
28567 {
28568 if(cmb.triggers[idx].label == name)
28569 {
28570 ret = dword(ri->combosref) | (dword(idx)<<24);
28571 break;
28572 }
28573 }
28574
28575 set_register(sarg1, ret);
28576 }
28577 break;
28578 }
28579 case CMBTRIG_GET_LABEL:
28580 {
28581 if(auto* trig = get_combo_trigger(ri->combotrigref))
28582 {
28583 auto aptr = get_register(sarg1) / 10000;
28584 if(ArrayH::setArray(aptr, trig->label, true) == SH::_Overflow)
28585 Z_scripterrlog("Array supplied to 'combotrigger->GetLabel()' not large enough,"
28586 " and couldn't be resized!\n");
28587 }
28588 break;
28589 }
28590 case CMBTRIG_SET_LABEL:
28591 {
28592 if (auto* trig = get_combo_trigger(ri->combotrigref))
28593 {
28594 auto aptr = get_register(sarg1) / 10000;
28595 ArrayH::getString(aptr, trig->label);
28596 }
28597 break;
28598 }
28599
28600 case REF_INC:
28601 {
28602 30108 int offset = ri->d[rSFRAME] + sarg1;
28603
1/2
✓ Branch 0 taken 30108 times.
✗ Branch 1 not taken.
30108 if (!ri->stack_pos_is_object.contains(offset))
28604 {
28605 assert(false);
28606 break;
28607 }
28608
28609 30108 uint32_t id = SH::read_stack(offset);
28610 30108 script_object_ref_inc(id);
28611 30108 break;
28612 }
28613 case REF_DEC:
28614 {
28615 int offset = ri->d[rSFRAME] + sarg1;
28616 if (!ri->stack_pos_is_object.contains(offset))
28617 {
28618 assert(false);
28619 break;
28620 }
28621
28622 uint32_t id = SH::read_stack(offset);
28623 script_object_ref_dec(id);
28624 break;
28625 }
28626 case REF_AUTORELEASE:
28627 {
28628 67629 uint32_t id = get_register(sarg1);
28629
2/2
✓ Branch 0 taken 8871 times.
✓ Branch 1 taken 58758 times.
67629 if (!util::contains(script_object_autorelease_pool, id))
28630 {
28631 58758 script_object_autorelease_pool.push_back(id);
28632
2/2
✓ Branch 0 taken 4250 times.
✓ Branch 1 taken 54508 times.
58758 if (auto object = get_script_object_checked(id))
28633 54508 object->ref_count++;
28634 58758 }
28635 67629 break;
28636 }
28637 case REF_COUNT:
28638 {
28639
1/2
✓ Branch 0 taken 1374 times.
✗ Branch 1 not taken.
1374 if (!use_testingst_start)
28640 {
28641 scripting_log_error_with_context("This function can only be used in test mode");
28642 break;
28643 }
28644
28645 1374 uint32_t id = get_register(sarg1);
28646 1374 auto object = get_script_object(id);
28647
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 1359 times.
1374 int count = object ? object->ref_count : -1;
28648 1374 set_register(sarg1, count);
28649 1374 break;
28650 }
28651 case MARK_TYPE_STACK:
28652 {
28653 30108 int offset = ri->d[rSFRAME] + sarg2;
28654
1/2
✓ Branch 0 taken 30108 times.
✗ Branch 1 not taken.
30108 if (offset < 0 || offset >= MAX_SCRIPT_REGISTERS)
28655 {
28656 assert(false);
28657 break;
28658 }
28659
1/2
✓ Branch 0 taken 30108 times.
✗ Branch 1 not taken.
30108 if (sarg1 < 0 || sarg1 > 1)
28660 {
28661 assert(false);
28662 break;
28663 }
28664
28665
1/2
✓ Branch 0 taken 30108 times.
✗ Branch 1 not taken.
30108 if (sarg1)
28666 30108 ri->stack_pos_is_object.insert(offset);
28667 else
28668 ri->stack_pos_is_object.erase(offset);
28669 30108 break;
28670 }
28671 case MARK_TYPE_REG:
28672 {
28673 2049 markRegisterType(sarg1, sarg2);
28674 2049 break;
28675 }
28676 case REF_REMOVE:
28677 {
28678 int offset = ri->d[rSFRAME] + sarg1;
28679 script_remove_object_ref(offset);
28680 break;
28681 }
28682 case GC:
28683 {
28684
1/2
✓ Branch 0 taken 226 times.
✗ Branch 1 not taken.
226 if (!use_testingst_start)
28685 {
28686 Z_error_fatal("GC can only be used in test mode\n");
28687 break;
28688 }
28689
28690 226 run_gc();
28691 226 break;
28692 }
28693 case SET_OBJECT:
28694 {
28695
1/2
✓ Branch 0 taken 1535 times.
✗ Branch 1 not taken.
1535 if (!(sarg1 >= GD(0) && sarg1 <= GD(MAX_SCRIPT_REGISTERS)))
28696 {
28697 assert(false);
28698 break;
28699 }
28700
28701 1535 int value = get_register(sarg2);
28702 1535 int index = sarg1-GD(0);
28703
1/2
✓ Branch 0 taken 1535 times.
✗ Branch 1 not taken.
1535 assert(game->global_d_types[index] != script_object_type::none);
28704 1535 script_object_ref_inc(value);
28705 1535 script_object_ref_dec(game->global_d[index]);
28706 1535 game->global_d[index] = value;
28707 1535 break;
28708 }
28709 case LOAD_INTERNAL_ARRAY:
28710 {
28711 4 do_load_internal_array();
28712 4 break;
28713 }
28714 case LOAD_INTERNAL_ARRAY_REF:
28715 {
28716 22 do_load_internal_array_ref();
28717 22 break;
28718 }
28719
28720 default:
28721 {
28722
1/2
✓ Branch 0 taken 1665401 times.
✗ Branch 1 not taken.
1665401 if (auto r = scripting_engine_run_command(scommand))
28723 {
28724
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1665401 times.
1665401 if (*r != RUNSCRIPT_OK)
28725 return *r;
28726 1665401 break;
28727 }
28728
28729 Z_scripterrlog("Invalid ZASM command %lu reached; terminating\n", scommand);
28730 hit_invalid_zasm = true;
28731 scommand = 0xFFFF;
28732 break;
28733 }
28734 }
28735
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1148294662 times.
1148294662 if(earlyretval == RUNSCRIPT_SELFDELETE)
28736 {
28737 earlyretval = -1;
28738 return RUNSCRIPT_SELFDELETE;
28739 }
28740
1/2
✓ Branch 0 taken 1148294662 times.
✗ Branch 1 not taken.
1148294662 if (ri->sp >= MAX_SCRIPT_REGISTERS)
28741 {
28742 if (old_script_funcrun)
28743 return RUNSCRIPT_OK;
28744 Z_scripterrlog("Stack over/underflow caused by command %d!\n", scommand);
28745 }
28746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1148294662 times.
1148294662 if(hit_invalid_zasm) break;
28747
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1148294662 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1148294662 if(old_script_funcrun && (ri->pc == MAX_PC || scommand == RETURN))
28748 return RUNSCRIPT_OK;
28749
28750
2/2
✓ Branch 0 taken 1145380860 times.
✓ Branch 1 taken 2913802 times.
1148294662 if (type == ScriptType::Combo)
28751 {
28752
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2913802 times.
2913802 if(combopos_modified == i)
28753 {
28754 //Combo changed! Abort script!
28755 return RUNSCRIPT_OK;
28756 }
28757 2913802 }
28758
2/2
✓ Branch 0 taken 83519 times.
✓ Branch 1 taken 1148211143 times.
1148294662 if(scommand != 0xFFFF)
28759 {
28760
2/2
✓ Branch 0 taken 1148209241 times.
✓ Branch 1 taken 1902 times.
1148211143 if(increment) ri->pc++;
28761 1902 else increment = true;
28762
1/2
✓ Branch 0 taken 1148211143 times.
✗ Branch 1 not taken.
1148211143 if ( ri->pc == MAX_PC ) //rolled over from overflow?
28763 {
28764 Z_scripterrlog("Script PC overflow! Too many ZASM lines?\n");
28765 ri->pc = curscript->pc;
28766 scommand = 0xFFFF;
28767 }
28768 1148211143 }
28769
28770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1148294662 times.
1148294662 if(earlyretval > -1) //Should this be below the 'commands_run += 1'? Unsure. -Em
28771 {
28772 auto v = earlyretval;
28773 earlyretval = -1;
28774 return earlyretval;
28775 }
28776
28777 // If running a JIT compiled script, we're only here to do a few commands.
28778 1148294662 commands_run += 1;
28779
4/4
✓ Branch 0 taken 1148244077 times.
✓ Branch 1 taken 50585 times.
✓ Branch 2 taken 1139584605 times.
✓ Branch 3 taken 8659472 times.
1148294662 if (is_jitted && commands_run == jitted_uncompiled_command_count) break;
28780 }
28781
2/2
✓ Branch 0 taken 810 times.
✓ Branch 1 taken 1166138930 times.
1166139740 if(script_funcrun) return RUNSCRIPT_OK;
28782
28783
2/2
✓ Branch 0 taken 1166138900 times.
✓ Branch 1 taken 30 times.
1166138930 if(!scriptCanSave)
28784 30 scriptCanSave=true;
28785
28786
2/2
✓ Branch 0 taken 1160090522 times.
✓ Branch 1 taken 6048408 times.
1166138930 if(scommand == WAITDRAW)
28787 {
28788
2/5
✗ Branch 0 not taken.
✓ Branch 1 taken 6032126 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 16282 times.
6048408 switch(type)
28789 {
28790 case ScriptType::Global:
28791 case ScriptType::Hero:
28792 case ScriptType::DMap:
28793 case ScriptType::OnMap:
28794 case ScriptType::ScriptedPassiveSubscreen:
28795 case ScriptType::ScriptedActiveSubscreen:
28796 case ScriptType::Screen:
28797 case ScriptType::Combo:
28798 case ScriptType::NPC:
28799 case ScriptType::Lwpn:
28800 case ScriptType::Ewpn:
28801 case ScriptType::ItemSprite:
28802 6032126 FFCore.waitdraw(type, i) = true;
28803 6032126 break;
28804
28805 case ScriptType::Item:
28806 {
28807 if (!get_qr(qr_NOITEMWAITDRAW))
28808 {
28809 FFCore.waitdraw(ScriptType::Item, i) = true;
28810 }
28811 break;
28812 }
28813
28814 case ScriptType::FFC:
28815 {
28816
2/2
✓ Branch 0 taken 1221 times.
✓ Branch 1 taken 15061 times.
16282 if ( !(get_qr(qr_NOFFCWAITDRAW)) )
28817 {
28818 15061 FFCore.waitdraw(ScriptType::FFC, i) = true;
28819 15061 }
28820 else
28821 {
28822 1221 Z_scripterrlog("Waitdraw cannot be used in script type: %s\n", "ffc, with Script Rule 'No FFC Waitdraw() enabled!");
28823 }
28824 16282 break;
28825 }
28826
28827 case ScriptType::Generic:
28828 case ScriptType::GenericFrozen:
28829 case ScriptType::EngineSubscreen:
28830 //No Waitdraw
28831 break;
28832
28833 default:
28834 Z_scripterrlog("Waitdraw cannot be used in script type: %s\n", ScriptTypeToString(type));
28835 break;
28836 }
28837 6048408 }
28838
28839
2/2
✓ Branch 0 taken 82734 times.
✓ Branch 1 taken 1166056196 times.
1166138930 if(scommand == 0xFFFF) //Quit/command list end reached/bad command
28840 {
28841 82734 script_exit_cleanup(no_dealloc);
28842 82734 return RUNSCRIPT_STOPPED;
28843 }
28844 else
28845 1166056196 ri->pc++;
28846
28847
2/2
✓ Branch 0 taken 26554293 times.
✓ Branch 1 taken 1139501903 times.
1166056196 if(jit_waiting_nop)
28848 26554293 return RUNSCRIPT_STOPPED;
28849
28850 1139501903 return RUNSCRIPT_OK;
28851 1166139758 }
28852
28853 1956 script_data* load_scrdata(ScriptType type, word script, int32_t i)
28854 {
28855
2/15
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 336 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1620 times.
✗ Branch 14 not taken.
1956 switch(type)
28856 {
28857 case ScriptType::FFC:
28858 return ffscripts[script];
28859 case ScriptType::NPC:
28860 return guyscripts[guys.getByUID(i)->script];
28861 case ScriptType::Lwpn:
28862 return lwpnscripts[Lwpns.getByUID(i)->weaponscript];
28863 case ScriptType::Ewpn:
28864 return ewpnscripts[Ewpns.getByUID(i)->weaponscript];
28865 case ScriptType::ItemSprite:
28866 return itemspritescripts[items.getByUID(i)->script];
28867 case ScriptType::Item:
28868 return itemscripts[script];
28869 case ScriptType::Global:
28870 return globalscripts[script];
28871 case ScriptType::Generic:
28872 case ScriptType::GenericFrozen:
28873 1620 return genericscripts[script];
28874 case ScriptType::Hero:
28875 return playerscripts[script];
28876 case ScriptType::DMap:
28877 return dmapscripts[script];
28878 case ScriptType::OnMap:
28879 case ScriptType::ScriptedActiveSubscreen:
28880 case ScriptType::ScriptedPassiveSubscreen:
28881 return dmapscripts[script];
28882 case ScriptType::Screen:
28883 return screenscripts[script];
28884 case ScriptType::Combo:
28885 return comboscripts[script];
28886 case ScriptType::EngineSubscreen:
28887 return subscreenscripts[script];
28888 }
28889 336 return nullptr;
28890 1956 }
28891
28892 //This keeps ffc scripts running beyond the first frame.
28893 14155916 int32_t ffscript_engine(const bool preload)
28894 {
28895
2/2
✓ Branch 0 taken 14121767 times.
✓ Branch 1 taken 34149 times.
14155916 if(preload)
28896 {
28897 34149 throwGenScriptEvent(GENSCR_EVENT_FFC_PRELOAD);
28898 34149 handle_region_load_trigger();
28899 34149 }
28900
28901
5/6
✓ Branch 0 taken 14153330 times.
✓ Branch 1 taken 2586 times.
✓ Branch 2 taken 1824243 times.
✓ Branch 3 taken 12329087 times.
✓ Branch 4 taken 1824243 times.
✗ Branch 5 not taken.
14155916 if (!FFCore.system_suspend[susptSCREENSCRIPTS] && FFCore.getQuestHeaderInfo(vZelda) >= 0x255 && !get_qr(qr_ZS_OLD_SUSPEND_FFC))
28902 {
28903 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
28904 if ((preload && scr->preloadscript) || !preload)
28905 {
28906 if (scr->script > 0 && FFCore.doscript(ScriptType::Screen, scr->screen))
28907 {
28908 ZScriptVersion::RunScript(ScriptType::Screen, scr->script, scr->screen);
28909 }
28910 }
28911 });
28912 }
28913
28914
2/2
✓ Branch 0 taken 2586 times.
✓ Branch 1 taken 14153330 times.
14155916 if (!FFCore.system_suspend[susptFFCSCRIPTS])
28915 {
28916 //intentional it's for compatability
28917
3/4
✓ Branch 0 taken 1824243 times.
✓ Branch 1 taken 12329087 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1824243 times.
14153330 if (FFCore.getQuestHeaderInfo(vZelda) >= 0x255 && get_qr(qr_ZS_OLD_SUSPEND_FFC))
28918 {
28919 4037562 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
28920
4/4
✓ Branch 0 taken 5140 times.
✓ Branch 1 taken 2208179 times.
✓ Branch 2 taken 5061 times.
✓ Branch 3 taken 2203118 times.
2213319 if ((preload && scr->preloadscript) || !preload)
28921 {
28922
3/4
✓ Branch 0 taken 50436 times.
✓ Branch 1 taken 2157822 times.
✓ Branch 2 taken 50436 times.
✗ Branch 3 not taken.
2208258 if (scr->script > 0 && FFCore.doscript(ScriptType::Screen, scr->screen))
28923 {
28924 50436 ZScriptVersion::RunScript(ScriptType::Screen, scr->script, scr->screen);
28925 50436 }
28926 2208258 }
28927 2213319 });
28928 1824243 }
28929
28930 449048555 for_every_ffc([&](const ffc_handle_t& ffc_handle) {
28931
2/2
✓ Branch 0 taken 11252367 times.
✓ Branch 1 taken 423642858 times.
434895225 if(ffc_handle.ffc->script == 0)
28932 423642858 return;
28933
28934
4/4
✓ Branch 0 taken 12920 times.
✓ Branch 1 taken 11239447 times.
✓ Branch 2 taken 10120 times.
✓ Branch 3 taken 2800 times.
11252367 if(preload && !(ffc_handle.ffc->flags&ffc_preload))
28935 10120 return;
28936
28937
4/4
✓ Branch 0 taken 11237688 times.
✓ Branch 1 taken 4559 times.
✓ Branch 2 taken 11152607 times.
✓ Branch 3 taken 85081 times.
11242247 if((ffc_handle.ffc->flags&ffc_ignoreholdup)==0 && Hero.getHoldClk()>0)
28938 85081 return;
28939
28940 11157166 ZScriptVersion::RunScript(ScriptType::FFC, ffc_handle.ffc->script, ffc_handle.id);
28941 434895225 });
28942 14153330 }
28943
28944
28945 14155916 return 0;
28946 }
28947
28948
28949
28950 ///----------------------------------------------------------------------------------------------------
28951
28952 417 void FFScript::user_files_init()
28953 {
28954 417 user_files.clear();
28955 417 }
28956
28957 417 void FFScript::user_dirs_init()
28958 {
28959 417 user_dirs.clear();
28960 417 }
28961 417 void FFScript::user_objects_init()
28962 {
28963 417 ::user_object_init();
28964 417 }
28965
28966 417 void FFScript::user_stacks_init()
28967 {
28968 417 user_stacks.clear();
28969 417 }
28970
28971 1077 void FFScript::user_rng_init()
28972 {
28973 1077 user_rngs.clear();
28974
2/2
✓ Branch 0 taken 275712 times.
✓ Branch 1 taken 1077 times.
276789 for(int32_t q = 0; q < MAX_USER_RNGS; ++q)
28975 {
28976 275712 replay_register_rng(&script_rnggens[q]);
28977
28978 // Just to seed it.
28979 275712 user_rng rng;
28980 275712 rng.set_gen(&script_rnggens[q]);
28981 275712 }
28982 1077 }
28983
28984 417 void FFScript::user_paldata_init()
28985 {
28986 417 user_paldatas.clear();
28987 417 }
28988
28989 417 void FFScript::user_websockets_init()
28990 {
28991 417 websocket_init();
28992 417 }
28993
28994 596 void FFScript::script_arrays_init()
28995 {
28996 596 script_arrays.clear();
28997 596 }
28998
28999 // Gotten from 'https://fileinfo.com/filetypes/executable'
29000
187/376
✓ Branch 0 taken 407 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 407 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 407 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 407 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 407 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 407 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 407 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 407 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 407 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 407 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 407 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 407 times.
✗ Branch 23 not taken.
✓ Branch 24 taken 407 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 407 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 407 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 407 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 407 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 407 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 407 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 407 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 407 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 407 times.
✗ Branch 43 not taken.
✓ Branch 44 taken 407 times.
✗ Branch 45 not taken.
✓ Branch 46 taken 407 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 407 times.
✗ Branch 49 not taken.
✓ Branch 50 taken 407 times.
✗ Branch 51 not taken.
✓ Branch 52 taken 407 times.
✗ Branch 53 not taken.
✓ Branch 54 taken 407 times.
✗ Branch 55 not taken.
✓ Branch 56 taken 407 times.
✗ Branch 57 not taken.
✓ Branch 58 taken 407 times.
✗ Branch 59 not taken.
✓ Branch 60 taken 407 times.
✗ Branch 61 not taken.
✓ Branch 62 taken 407 times.
✗ Branch 63 not taken.
✓ Branch 64 taken 407 times.
✗ Branch 65 not taken.
✓ Branch 66 taken 407 times.
✗ Branch 67 not taken.
✓ Branch 68 taken 407 times.
✗ Branch 69 not taken.
✓ Branch 70 taken 407 times.
✗ Branch 71 not taken.
✓ Branch 72 taken 407 times.
✗ Branch 73 not taken.
✓ Branch 74 taken 407 times.
✗ Branch 75 not taken.
✓ Branch 76 taken 407 times.
✗ Branch 77 not taken.
✓ Branch 78 taken 407 times.
✗ Branch 79 not taken.
✓ Branch 80 taken 407 times.
✗ Branch 81 not taken.
✓ Branch 82 taken 407 times.
✗ Branch 83 not taken.
✓ Branch 84 taken 407 times.
✗ Branch 85 not taken.
✓ Branch 86 taken 407 times.
✗ Branch 87 not taken.
✓ Branch 88 taken 407 times.
✗ Branch 89 not taken.
✓ Branch 90 taken 407 times.
✗ Branch 91 not taken.
✓ Branch 92 taken 407 times.
✗ Branch 93 not taken.
✓ Branch 94 taken 407 times.
✗ Branch 95 not taken.
✓ Branch 96 taken 407 times.
✗ Branch 97 not taken.
✓ Branch 98 taken 407 times.
✗ Branch 99 not taken.
✓ Branch 100 taken 407 times.
✗ Branch 101 not taken.
✓ Branch 102 taken 407 times.
✗ Branch 103 not taken.
✓ Branch 104 taken 407 times.
✗ Branch 105 not taken.
✓ Branch 106 taken 407 times.
✗ Branch 107 not taken.
✓ Branch 108 taken 407 times.
✗ Branch 109 not taken.
✓ Branch 110 taken 407 times.
✗ Branch 111 not taken.
✓ Branch 112 taken 407 times.
✗ Branch 113 not taken.
✓ Branch 114 taken 407 times.
✗ Branch 115 not taken.
✓ Branch 116 taken 407 times.
✗ Branch 117 not taken.
✓ Branch 118 taken 407 times.
✗ Branch 119 not taken.
✓ Branch 120 taken 407 times.
✗ Branch 121 not taken.
✓ Branch 122 taken 407 times.
✗ Branch 123 not taken.
✓ Branch 124 taken 407 times.
✗ Branch 125 not taken.
✓ Branch 126 taken 407 times.
✗ Branch 127 not taken.
✓ Branch 128 taken 407 times.
✗ Branch 129 not taken.
✓ Branch 130 taken 407 times.
✗ Branch 131 not taken.
✓ Branch 132 taken 407 times.
✗ Branch 133 not taken.
✓ Branch 134 taken 407 times.
✗ Branch 135 not taken.
✓ Branch 136 taken 407 times.
✗ Branch 137 not taken.
✓ Branch 138 taken 407 times.
✗ Branch 139 not taken.
✓ Branch 140 taken 407 times.
✗ Branch 141 not taken.
✓ Branch 142 taken 407 times.
✗ Branch 143 not taken.
✓ Branch 144 taken 407 times.
✗ Branch 145 not taken.
✓ Branch 146 taken 407 times.
✗ Branch 147 not taken.
✓ Branch 148 taken 407 times.
✗ Branch 149 not taken.
✓ Branch 150 taken 407 times.
✗ Branch 151 not taken.
✓ Branch 152 taken 407 times.
✗ Branch 153 not taken.
✓ Branch 154 taken 407 times.
✗ Branch 155 not taken.
✓ Branch 156 taken 407 times.
✗ Branch 157 not taken.
✓ Branch 158 taken 407 times.
✗ Branch 159 not taken.
✓ Branch 160 taken 407 times.
✗ Branch 161 not taken.
✓ Branch 162 taken 407 times.
✗ Branch 163 not taken.
✓ Branch 164 taken 407 times.
✗ Branch 165 not taken.
✓ Branch 166 taken 407 times.
✗ Branch 167 not taken.
✓ Branch 168 taken 407 times.
✗ Branch 169 not taken.
✓ Branch 170 taken 407 times.
✗ Branch 171 not taken.
✓ Branch 172 taken 407 times.
✗ Branch 173 not taken.
✓ Branch 174 taken 407 times.
✗ Branch 175 not taken.
✓ Branch 176 taken 407 times.
✗ Branch 177 not taken.
✓ Branch 178 taken 407 times.
✗ Branch 179 not taken.
✓ Branch 180 taken 407 times.
✗ Branch 181 not taken.
✓ Branch 182 taken 407 times.
✗ Branch 183 not taken.
✓ Branch 184 taken 407 times.
✗ Branch 185 not taken.
✓ Branch 186 taken 407 times.
✗ Branch 187 not taken.
✓ Branch 188 taken 407 times.
✗ Branch 189 not taken.
✓ Branch 190 taken 407 times.
✗ Branch 191 not taken.
✓ Branch 192 taken 407 times.
✗ Branch 193 not taken.
✓ Branch 194 taken 407 times.
✗ Branch 195 not taken.
✓ Branch 196 taken 407 times.
✗ Branch 197 not taken.
✓ Branch 198 taken 407 times.
✗ Branch 199 not taken.
✓ Branch 200 taken 407 times.
✗ Branch 201 not taken.
✓ Branch 202 taken 407 times.
✗ Branch 203 not taken.
✓ Branch 204 taken 407 times.
✗ Branch 205 not taken.
✓ Branch 206 taken 407 times.
✗ Branch 207 not taken.
✓ Branch 208 taken 407 times.
✗ Branch 209 not taken.
✓ Branch 210 taken 407 times.
✗ Branch 211 not taken.
✓ Branch 212 taken 407 times.
✗ Branch 213 not taken.
✓ Branch 214 taken 407 times.
✗ Branch 215 not taken.
✓ Branch 216 taken 407 times.
✗ Branch 217 not taken.
✓ Branch 218 taken 407 times.
✗ Branch 219 not taken.
✓ Branch 220 taken 407 times.
✗ Branch 221 not taken.
✓ Branch 222 taken 407 times.
✗ Branch 223 not taken.
✓ Branch 224 taken 407 times.
✗ Branch 225 not taken.
✓ Branch 226 taken 407 times.
✗ Branch 227 not taken.
✓ Branch 228 taken 407 times.
✗ Branch 229 not taken.
✓ Branch 230 taken 407 times.
✗ Branch 231 not taken.
✓ Branch 232 taken 407 times.
✗ Branch 233 not taken.
✓ Branch 234 taken 407 times.
✗ Branch 235 not taken.
✓ Branch 236 taken 407 times.
✗ Branch 237 not taken.
✓ Branch 238 taken 407 times.
✗ Branch 239 not taken.
✓ Branch 240 taken 407 times.
✗ Branch 241 not taken.
✓ Branch 242 taken 407 times.
✗ Branch 243 not taken.
✓ Branch 244 taken 407 times.
✗ Branch 245 not taken.
✓ Branch 246 taken 407 times.
✗ Branch 247 not taken.
✓ Branch 248 taken 407 times.
✗ Branch 249 not taken.
✓ Branch 250 taken 407 times.
✗ Branch 251 not taken.
✓ Branch 252 taken 407 times.
✗ Branch 253 not taken.
✓ Branch 254 taken 407 times.
✗ Branch 255 not taken.
✓ Branch 256 taken 407 times.
✗ Branch 257 not taken.
✓ Branch 258 taken 407 times.
✗ Branch 259 not taken.
✓ Branch 260 taken 407 times.
✗ Branch 261 not taken.
✓ Branch 262 taken 407 times.
✗ Branch 263 not taken.
✓ Branch 264 taken 407 times.
✗ Branch 265 not taken.
✓ Branch 266 taken 407 times.
✗ Branch 267 not taken.
✓ Branch 268 taken 407 times.
✗ Branch 269 not taken.
✓ Branch 270 taken 407 times.
✗ Branch 271 not taken.
✓ Branch 272 taken 407 times.
✗ Branch 273 not taken.
✓ Branch 274 taken 407 times.
✗ Branch 275 not taken.
✓ Branch 276 taken 407 times.
✗ Branch 277 not taken.
✓ Branch 278 taken 407 times.
✗ Branch 279 not taken.
✓ Branch 280 taken 407 times.
✗ Branch 281 not taken.
✓ Branch 282 taken 407 times.
✗ Branch 283 not taken.
✓ Branch 284 taken 407 times.
✗ Branch 285 not taken.
✓ Branch 286 taken 407 times.
✗ Branch 287 not taken.
✓ Branch 288 taken 407 times.
✗ Branch 289 not taken.
✓ Branch 290 taken 407 times.
✗ Branch 291 not taken.
✓ Branch 292 taken 407 times.
✗ Branch 293 not taken.
✓ Branch 294 taken 407 times.
✗ Branch 295 not taken.
✓ Branch 296 taken 407 times.
✗ Branch 297 not taken.
✓ Branch 298 taken 407 times.
✗ Branch 299 not taken.
✓ Branch 300 taken 407 times.
✗ Branch 301 not taken.
✓ Branch 302 taken 407 times.
✗ Branch 303 not taken.
✓ Branch 304 taken 407 times.
✗ Branch 305 not taken.
✓ Branch 306 taken 407 times.
✗ Branch 307 not taken.
✓ Branch 308 taken 407 times.
✗ Branch 309 not taken.
✓ Branch 310 taken 407 times.
✗ Branch 311 not taken.
✓ Branch 312 taken 407 times.
✗ Branch 313 not taken.
✓ Branch 314 taken 407 times.
✗ Branch 315 not taken.
✓ Branch 316 taken 407 times.
✗ Branch 317 not taken.
✓ Branch 318 taken 407 times.
✗ Branch 319 not taken.
✓ Branch 320 taken 407 times.
✗ Branch 321 not taken.
✓ Branch 322 taken 407 times.
✗ Branch 323 not taken.
✓ Branch 324 taken 407 times.
✗ Branch 325 not taken.
✓ Branch 326 taken 407 times.
✗ Branch 327 not taken.
✓ Branch 328 taken 407 times.
✗ Branch 329 not taken.
✓ Branch 330 taken 407 times.
✗ Branch 331 not taken.
✓ Branch 332 taken 407 times.
✗ Branch 333 not taken.
✓ Branch 334 taken 407 times.
✗ Branch 335 not taken.
✓ Branch 336 taken 407 times.
✗ Branch 337 not taken.
✓ Branch 338 taken 407 times.
✗ Branch 339 not taken.
✓ Branch 340 taken 407 times.
✗ Branch 341 not taken.
✓ Branch 342 taken 407 times.
✗ Branch 343 not taken.
✓ Branch 344 taken 407 times.
✗ Branch 345 not taken.
✓ Branch 346 taken 407 times.
✗ Branch 347 not taken.
✓ Branch 348 taken 407 times.
✗ Branch 349 not taken.
✓ Branch 350 taken 407 times.
✗ Branch 351 not taken.
✓ Branch 352 taken 407 times.
✗ Branch 353 not taken.
✓ Branch 354 taken 407 times.
✗ Branch 355 not taken.
✓ Branch 356 taken 407 times.
✗ Branch 357 not taken.
✓ Branch 358 taken 407 times.
✗ Branch 359 not taken.
✓ Branch 360 taken 407 times.
✗ Branch 361 not taken.
✓ Branch 362 taken 407 times.
✗ Branch 363 not taken.
✓ Branch 364 taken 407 times.
✗ Branch 365 not taken.
✓ Branch 366 taken 407 times.
✗ Branch 367 not taken.
✓ Branch 368 taken 407 times.
✗ Branch 369 not taken.
✓ Branch 370 taken 407 times.
✗ Branch 371 not taken.
✓ Branch 372 taken 407 times.
✗ Branch 373 not taken.
✗ Branch 374 not taken.
✗ Branch 375 not taken.
407 static std::set<std::string> banned_extensions = {".xlm",".caction",".8ck", ".actc",".a6p", ".m3g",".run",".workflow",".otm",".apk",".fxp",".73k",".0xe",".exe",".cmd",".jsx",".scar",".wcm",".jar",".ebs2",".ipa",".xap",".ba_",".ac",".bin",".vlx",".icd",".elf",".xbap",".89k",".widget",".a7r",".ex_",".zl9",".cgi",".scr",".coffee",".ahk",".plsc",".air",".ear",".app",".scptd",".xys",".hms",".cyw",".ebm",".pwc",".xqt",".msl",".seed",".vexe",".ebs",".mcr",".gpu",".celx",".wsh",".frs",".vxp",".action",".com",".out",".gadget",".command",".script",".rfu",".tcp",".widget",".ex4",".bat",".cof",".phar",".rxe",".scb",".ms",".isu",".fas",".mlx",".gpe",".mcr",".mrp",".u3p",".js",".acr",".epk",".exe1",".jsf",".rbf",".rgs",".vpm",".ecf",".hta",".dld",".applescript",".prg",".pyc",".spr",".nexe",".server",".appimage",".pyo",".dek",".mrc",".fpi",".rpj",".iim",".vbs",".pif",".mel",".scpt",".csh",".paf",".ws",".mm",".acc",".ex5",".mac",".plx",".snap",".ps1",".vdo",".mxe",".gs",".osx",".sct",".wiz",".x86",".e_e",".fky",".prg",".fas",".azw2",".actm",".cel",".tiapp",".thm",".kix",".wsf",".vbe",".lo",".ls",".tms",".ezs",".ds",".n",".esh",".vbscript",".arscript",".qit",".pex",".dxl",".wpm",".s2a",".sca",".prc",".shb",".rbx",".jse",".beam",".udf",".mem",".kx",".ksh",".rox",".upx",".ms",".mam",".btm",".es",".asb",".ipf",".mio",".sbs",".hpf",".ita",".eham",".ezt",".dmc",".qpx",".ore",".ncl",".exopc",".smm",".pvd",".ham",".wpk"};
29001
29002 // If the path is valid, returns an absolute path under the quest "Files" directory.
29003 2 static expected<std::string, std::string> parse_user_path(const std::string& user_path, bool is_file)
29004 {
29005 // First check for non-portable path characters.
29006 static const char* invalid_chars = "<>|?*&^$#\":";
29007
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (auto index = user_path.find_first_of(invalid_chars) != string::npos)
29008 {
29009 return make_unexpected(fmt::format("Bad path: {} - invalid character {}", user_path, user_path[index]));
29010 }
29011
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 2 times.
56 for (char c : user_path)
29012 {
29013
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if (c < 32)
29014 return make_unexpected(fmt::format("Bad path: {} - invalid control character {:#x}", user_path, c));
29015 }
29016
29017 // Any leading slashes are ignored.
29018 // This makes path always relative.
29019 2 const char* path = user_path.c_str();
29020
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 while (path[0] == '/' || path[0] == '\\')
29021 path++;
29022
29023 // Normalize `user_path` and check if it accesses a parent path.
29024
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 auto files_path = fs::absolute(fs::path(qst_files_path));
29025
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 auto normalized_path = fs::path(path).lexically_normal();
29026
5/12
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
4 if (!normalized_path.empty() && normalized_path.begin()->string() == "..")
29027 {
29028 return make_unexpected(fmt::format("Bad path: {} (resolved to {}) - cannot access filesystem outside {} (too many ..?)",
29029 path, normalized_path.string(), files_path.string()));
29030 }
29031
29032
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 auto resolved_path = files_path / normalized_path;
29033
29034 // The above should be enough to guarantee that `resolved_path` is within
29035 // the quest "Files" folder, but check to be safe.
29036
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 auto mismatch_pair = std::mismatch(
29037 2 resolved_path.begin(), resolved_path.end(),
29038 2 files_path.begin(), files_path.end());
29039 2 bool is_subpath = mismatch_pair.second == files_path.end();
29040
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!is_subpath)
29041 {
29042 return make_unexpected(fmt::format("Bad path: {} (resolved to {}) - cannot access filesystem outside {}",
29043 user_path, resolved_path.string(), files_path.string()));
29044 }
29045
29046 // Any extension other than banned ones, including no extension, is allowed.
29047
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 if (is_file && resolved_path.has_extension())
29048 {
29049
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 auto ext = resolved_path.extension().string();
29050
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (banned_extensions.find(ext) != banned_extensions.end())
29051 return make_unexpected(fmt::format("Bad path: {} - banned extension", user_path));
29052
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 }
29053
29054
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (is_file && !resolved_path.has_filename())
29055 return make_unexpected(fmt::format("Bad path: {} - missing filename", user_path));
29056
29057 // https://stackoverflow.com/a/31976060/2788187
29058
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (is_file)
29059 {
29060 static auto banned_fnames = {
29061 "..", ".", "AUX", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6",
29062 "COM7", "COM8", "COM9", "CON", "LPT1", "LPT2", "LPT3", "LPT4",
29063 "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", "NUL", "PRN",
29064 };
29065
29066
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 auto stem = resolved_path.stem().string();
29067
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 auto fname = resolved_path.filename().string();
29068
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 bool banned = std::find(std::begin(banned_fnames), std::end(banned_fnames), stem) != std::end(banned_fnames);
29069
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 banned |= fname.ends_with(".") || fname.ends_with(" ");
29070
29071
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (banned)
29072 return make_unexpected(fmt::format("Bad path: {} - banned filename", user_path));
29073
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 }
29074
29075
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 return resolved_path.string();
29076 2 }
29077
29078 bool FFScript::get_scriptfile_path(char* buf, const char* path)
29079 {
29080 while((path[0] == '/' || path[0] == '\\') && path[0]) ++path;
29081 if(path[0])
29082 sprintf(buf, "%s%c%s", qst_files_path, PATH_SLASH, path);
29083 else sprintf(buf, "%s", qst_files_path);
29084 return true;
29085 }
29086
29087 280 void check_file_error(int32_t ref)
29088 {
29089
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 280 times.
280 if(user_file* f = checkFile(ref, true, true))
29090 {
29091 280 int32_t err = ferror(f->file);
29092
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 280 times.
280 if(err != 0)
29093 {
29094 Z_scripterrlog("File with UID '%ld' encountered an error.\n", ref);
29095 Z_scripterrlog("File error: %s\n", strerror(err));
29096 }
29097 280 }
29098 280 }
29099
29100 2 void FFScript::do_fopen(const bool v, const char* f_mode)
29101 {
29102 2 int32_t arrayptr = SH::get_arg(sarg1, v);
29103 2 string user_path;
29104
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 ArrayH::getString(arrayptr, user_path, 512);
29105
29106 2 ri->d[rEXP1] = 0L; //Presume failure; update to 10000L on success
29107 2 ri->d[rEXP2] = 0;
29108
29109 2 std::string resolved_path;
29110
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 if (auto r = parse_user_path(user_path, true); !r)
29111 {
29112 scripting_log_error_with_context("Error: {}", r.error());
29113 return;
29114
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 } else resolved_path = r.value();
29115
29116
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 user_file* f = checkFile(ri->fileref, false, true);
29117
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!f) //auto-allocate
29118 {
29119
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 ri->fileref = user_files.get_free();
29120
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 f = checkFile(ri->fileref, false, true);
29121 2 }
29122 2 ri->d[rEXP2] = ri->fileref; //Returns to the variable!
29123
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(f)
29124 {
29125
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 f->close(); //Close the old FILE* before overwriting it!
29126 2 bool create = false;
29127
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4 times.
5 for(int32_t q = 0; f_mode[q]; ++q)
29128 {
29129
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
4 if(f_mode[q] == 'w' || f_mode[q] == 'a')
29130 {
29131 1 create = true;
29132 1 break;
29133 }
29134 3 }
29135
4/6
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 if(!create || make_dirs_for_file(resolved_path))
29136 {
29137
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 f->file = fopen(resolved_path.c_str(), f_mode);
29138
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 fflush(f->file);
29139
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 zc_chmod(resolved_path.c_str(), SCRIPT_FILE_MODE);
29140
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 f->setPath(resolved_path.c_str());
29141 //r+; read-write, will not create if does not exist, will not delete content if does exist.
29142 //w+; read-write, will create if does not exist, will delete all content if does exist.
29143
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if(f->file)
29144 {
29145 1 ri->d[rEXP1] = 10000L; //Success
29146 1 return;
29147 }
29148 1 }
29149 else
29150 {
29151 Z_scripterrlog("Script failed to create directories for file path '%s'.\n", resolved_path.c_str());
29152 ri->d[rEXP2] = 0;
29153 return;
29154 }
29155 1 }
29156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 }
29157
29158 void FFScript::do_fremove()
29159 {
29160 if(user_file* f = checkFile(ri->fileref, true))
29161 {
29162 zprint2("Removing file %d\n", ri->fileref);
29163 ri->d[rEXP1] = f->do_remove() ? 0L : 10000L;
29164 }
29165 else ri->d[rEXP1] = 0L;
29166 }
29167
29168 void FFScript::do_fclose()
29169 {
29170 if(user_file* f = checkFile(ri->fileref, false, true))
29171 {
29172 f->close();
29173 }
29174 //No else. If invalid, no error is thrown.
29175 }
29176
29177 void FFScript::do_allocate_file()
29178 {
29179 //Get a file and return it
29180 ri->fileref = user_files.get_free();
29181 ri->d[rEXP2] = ri->fileref; //Return to ptr
29182 ri->d[rEXP1] = (ri->d[rEXP2] == 0 ? 0L : 10000L);
29183 }
29184
29185 1 void FFScript::do_deallocate_file()
29186 {
29187 1 user_file* f = checkFile(ri->fileref, false, true);
29188
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(f) free_script_object(f->id);
29189 1 }
29190
29191 void FFScript::do_file_isallocated() //Returns true if file is allocated
29192 {
29193 user_file* f = checkFile(ri->fileref, false, true);
29194 ri->d[rEXP1] = (f) ? 10000L : 0L;
29195 }
29196
29197 void FFScript::do_file_isvalid() //Returns true if file is allocated and has an open FILE*
29198 {
29199 user_file* f = checkFile(ri->fileref, true, true);
29200 ri->d[rEXP1] = (f) ? 10000L : 0L;
29201 }
29202
29203 1 void FFScript::do_fflush()
29204 {
29205 1 ri->d[rEXP1] = 0L;
29206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(user_file* f = checkFile(ri->fileref, true))
29207 {
29208
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!fflush(f->file))
29209 1 ri->d[rEXP1] = 10000L;
29210 1 check_file_error(ri->fileref);
29211 1 }
29212 1 }
29213
29214 void FFScript::do_file_readchars()
29215 {
29216 if(user_file* f = checkFile(ri->fileref, true))
29217 {
29218 uint32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
29219 int32_t count = get_register(sarg2) / 10000;
29220 if(count == 0) return;
29221 int32_t arrayptr = get_register(sarg1);
29222 ArrayManager am(arrayptr);
29223 int32_t sz = am.size();
29224 if(sz <= 0)
29225 return;
29226 if(pos >= sz)
29227 {
29228 Z_scripterrlog("Pos (%d) passed to %s is outside the bounds of array %d. Aborting.\n", pos, "ReadChars()", arrayptr);
29229 return;
29230 }
29231 if(count < 0 || unsigned(count) > sz-pos) count = sz-pos;
29232 int32_t limit = pos+count;
29233 char c;
29234 word q;
29235 ri->d[rEXP1] = 0;
29236 for(q = pos; q < limit; ++q)
29237 {
29238 c = fgetc(f->file);
29239 if(feof(f->file) || ferror(f->file))
29240 break;
29241 if(c <= 0)
29242 break;
29243 am.set(q,c * 10000L);
29244 ++ri->d[rEXP1]; //Don't count nullchar towards length
29245 }
29246 if(q >= limit)
29247 {
29248 --q;
29249 --ri->d[rEXP1];
29250 ungetc(am.get(q), f->file); //Put the character back before overwriting it
29251 }
29252 am.set(q,0); //Force null-termination
29253 ri->d[rEXP1] *= 10000L;
29254 check_file_error(ri->fileref);
29255 return;
29256 }
29257 ri->d[rEXP1] = 0L;
29258 }
29259 void FFScript::do_file_readbytes()
29260 {
29261 if(user_file* f = checkFile(ri->fileref, true))
29262 {
29263 uint32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
29264 int32_t count = get_register(sarg2) / 10000;
29265 if(count == 0) return;
29266 int32_t arrayptr = get_register(sarg1);
29267 ArrayManager am(arrayptr);
29268 int32_t sz = am.size();
29269 if(sz <= 0)
29270 return;
29271 if(pos >= sz)
29272 {
29273 Z_scripterrlog("Pos (%d) passed to %s is outside the bounds of array %d. Aborting.\n", pos, "ReadBytes()", arrayptr);
29274 return;
29275 }
29276 if(count < 0 || unsigned(count) > sz-pos) count = sz-pos;
29277 std::vector<uint8_t> data(count);
29278 ri->d[rEXP1] = 10000L * fread((void*)&(data[0]), 1, count, f->file);
29279 for(int32_t q = 0; q < count; ++q)
29280 {
29281 am.set(q+pos, 10000L * data[q]);
29282 }
29283 check_file_error(ri->fileref);
29284 return;
29285 }
29286 ri->d[rEXP1] = 0L;
29287 }
29288 void FFScript::do_file_readstring()
29289 {
29290 if(user_file* f = checkFile(ri->fileref, true))
29291 {
29292 int32_t arrayptr = get_register(sarg1);
29293 ArrayManager am(arrayptr);
29294 int32_t sz = am.size();
29295 if(sz <= 0)
29296 return;
29297 int32_t limit = sz;
29298 int32_t c;
29299 word q;
29300 ri->d[rEXP1] = 0;
29301 for(q = 0; q < limit; ++q)
29302 {
29303 c = fgetc(f->file);
29304 if(feof(f->file) || ferror(f->file))
29305 break;
29306 if(c <= 0)
29307 break;
29308 am.set(q,c * 10000L);
29309 ++ri->d[rEXP1]; //Don't count nullchar towards length
29310 if(c == '\n')
29311 {
29312 ++q;
29313 break;
29314 }
29315 }
29316 if(q >= limit)
29317 {
29318 --q;
29319 --ri->d[rEXP1];
29320 ungetc(am.get(q), f->file); //Put the character back before overwriting it
29321 }
29322 am.set(q,0); //Force null-termination
29323 ri->d[rEXP1] *= 10000L;
29324 check_file_error(ri->fileref);
29325 return;
29326 }
29327 ri->d[rEXP1] = 0L;
29328 }
29329 void FFScript::do_file_readints()
29330 {
29331 if(user_file* f = checkFile(ri->fileref, true))
29332 {
29333 uint32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
29334 int32_t count = get_register(sarg2) / 10000;
29335 if(count == 0) return;
29336 int32_t arrayptr = get_register(sarg1);
29337 ArrayManager am(arrayptr);
29338 int32_t sz = am.size();
29339 if(sz <= 0)
29340 return;
29341 if(pos >= sz)
29342 {
29343 Z_scripterrlog("Pos (%d) passed to %s is outside the bounds of array %d. Aborting.\n", pos, "ReadInts()", arrayptr);
29344 return;
29345 }
29346 if(count < 0 || unsigned(count) > sz-pos) count = sz-pos;
29347
29348 std::vector<int32_t> data(count);
29349 ri->d[rEXP1] = 10000L * fread((void*)&(data[0]), 4, count, f->file);
29350 for(int32_t q = 0; q < count; ++q)
29351 {
29352 am.set(q+pos,data[q]);
29353 }
29354 check_file_error(ri->fileref);
29355 return;
29356 }
29357 ri->d[rEXP1] = 0L;
29358 }
29359 void FFScript::do_file_writechars()
29360 {
29361 if(user_file* f = checkFile(ri->fileref, true))
29362 {
29363 int32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
29364 int32_t count = get_register(sarg2) / 10000;
29365 if(count == 0) return;
29366 if(count == -1 || count > (MAX_ZC_ARRAY_SIZE-pos)) count = MAX_ZC_ARRAY_SIZE-pos;
29367 int32_t arrayptr = get_register(sarg1);
29368 string output;
29369 ArrayH::getString(arrayptr, output, count, pos);
29370 uint32_t q = 0;
29371 for(; q < output.length(); ++q)
29372 {
29373 if(fputc(output[q], f->file)<0)
29374 break;
29375 }
29376 ri->d[rEXP1] = q * 10000L;
29377 check_file_error(ri->fileref);
29378 return;
29379 }
29380 ri->d[rEXP1] = 0L;
29381 }
29382
29383 void FFScript::do_file_writebytes()
29384 {
29385 if(user_file* f = checkFile(ri->fileref, true))
29386 {
29387 uint32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
29388 int32_t arg = get_register(sarg2) / 10000;
29389 if(arg == 0) return;
29390 uint32_t count = ((arg<0 || unsigned(arg) >(MAX_ZC_ARRAY_SIZE - pos)) ? MAX_ZC_ARRAY_SIZE - pos : unsigned(arg));
29391 int32_t arrayptr = get_register(sarg1);
29392 string output;
29393 ArrayManager am(arrayptr);
29394 if(am.invalid()) return;
29395 int32_t sz = am.size();
29396 if(sz <= 0)
29397 return;
29398 if(pos >= sz)
29399 {
29400 Z_scripterrlog("Pos (%d) passed to %s is outside the bounds of array %d. Aborting.\n", pos, "WriteBytes()", arrayptr);
29401 return;
29402 }
29403 if (count > sz-pos) count = sz-pos;
29404 std::vector<uint8_t> data(count);
29405 for(uint32_t q = 0; q < count; ++q)
29406 {
29407 data[q] = am.get(q+pos) / 10000;
29408 }
29409 ri->d[rEXP1] = 10000L * fwrite((const void*)&(data[0]), 1, count, f->file);
29410 check_file_error(ri->fileref);
29411 return;
29412 }
29413 ri->d[rEXP1] = 0L;
29414 }
29415 279 void FFScript::do_file_writestring()
29416 {
29417
1/2
✓ Branch 0 taken 279 times.
✗ Branch 1 not taken.
279 if(user_file* f = checkFile(ri->fileref, true))
29418 {
29419 279 int32_t arrayptr = get_register(sarg1);
29420 279 string output;
29421
1/2
✓ Branch 0 taken 279 times.
✗ Branch 1 not taken.
279 ArrayH::getString(arrayptr, output, ZSCRIPT_MAX_STRING_CHARS);
29422 279 uint32_t q = 0;
29423
2/2
✓ Branch 0 taken 12719 times.
✓ Branch 1 taken 279 times.
12998 for(; q < output.length(); ++q)
29424 {
29425
3/6
✓ Branch 0 taken 12719 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12719 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12719 times.
✗ Branch 5 not taken.
12719 if(fputc(output[q], f->file)<0)
29426 break;
29427 12719 }
29428 279 ri->d[rEXP1] = q * 10000L;
29429
1/2
✓ Branch 0 taken 279 times.
✗ Branch 1 not taken.
279 check_file_error(ri->fileref);
29430 return;
29431 279 }
29432 ri->d[rEXP1] = 0L;
29433 279 }
29434 void FFScript::do_file_writeints()
29435 {
29436 if(user_file* f = checkFile(ri->fileref, true))
29437 {
29438 uint32_t pos = zc_max(ri->d[rINDEX] / 10000,0);
29439 int32_t count = get_register(sarg2) / 10000;
29440 if(count == 0) return;
29441 int32_t arrayptr = get_register(sarg1);
29442 ArrayManager am(arrayptr);
29443 if(am.invalid()) return;
29444 int32_t sz = am.size();
29445 if(sz <= 0)
29446 return;
29447 if(pos >= sz)
29448 {
29449 Z_scripterrlog("Pos (%d) passed to %s is outside the bounds of array %d. Aborting.\n", pos, "WriteInts()", arrayptr);
29450 return;
29451 }
29452
29453 if(count < 0 || unsigned(count) > sz-pos) count = sz-pos;
29454 std::vector<int32_t> data(count);
29455 for(int32_t q = 0; q < count; ++q)
29456 {
29457 data[q] = am.get(q+pos);
29458 }
29459 ri->d[rEXP1] = 10000L * fwrite((const void*)&(data[0]), 4, count, f->file);
29460 check_file_error(ri->fileref);
29461 return;
29462 }
29463 ri->d[rEXP1] = 0L;
29464 }
29465
29466 void FFScript::do_file_getchar()
29467 {
29468 if(user_file* f = checkFile(ri->fileref, true))
29469 {
29470 ri->d[rEXP1] = fgetc(f->file) * 10000L;
29471 check_file_error(ri->fileref);
29472 return;
29473 }
29474 ri->d[rEXP1] = -10000L; //-1 == EOF; error value
29475 }
29476 void FFScript::do_file_putchar()
29477 {
29478 if(user_file* f = checkFile(ri->fileref, true))
29479 {
29480 int32_t c = get_register(sarg1) / 10000;
29481 if(char(c) != c)
29482 {
29483 Z_scripterrlog("Invalid character val %d passed to PutChar(); value will overflow.", c);
29484 c = char(c);
29485 }
29486 ri->d[rEXP1] = fputc(c, f->file) * 10000L;
29487 check_file_error(ri->fileref);
29488 return;
29489 }
29490 ri->d[rEXP1] = -10000L; //-1 == EOF; error value
29491 }
29492 void FFScript::do_file_ungetchar()
29493 {
29494 if(user_file* f = checkFile(ri->fileref, true))
29495 {
29496 int32_t c = get_register(sarg1) / 10000;
29497 if(char(c) != c)
29498 {
29499 Z_scripterrlog("Invalid character val %d passed to UngetChar(); value will overflow.", c);
29500 c = char(c);
29501 }
29502 ri->d[rEXP1] = ungetc(c,f->file) * 10000L;
29503 check_file_error(ri->fileref);
29504 return;
29505 }
29506 ri->d[rEXP1] = -10000L; //-1 == EOF; error value
29507 }
29508
29509 void FFScript::do_file_seek()
29510 {
29511 if(user_file* f = checkFile(ri->fileref, true))
29512 {
29513 int32_t pos = get_register(sarg1); //NOT /10000 -V
29514 int32_t origin = get_register(sarg2) ? SEEK_CUR : SEEK_SET;
29515 ri->d[rEXP1] = fseek(f->file, pos, origin) ? 0L : 10000L;
29516 check_file_error(ri->fileref);
29517 return;
29518 }
29519 ri->d[rEXP1] = 0;
29520 }
29521 void FFScript::do_file_rewind()
29522 {
29523 if(user_file* f = checkFile(ri->fileref, true))
29524 {
29525 //fseek(f->file, 0L, SEEK_END);
29526 rewind(f->file);
29527 check_file_error(ri->fileref);
29528 }
29529 }
29530 void FFScript::do_file_clearerr()
29531 {
29532 if(user_file* f = checkFile(ri->fileref, true))
29533 {
29534 clearerr(f->file);
29535 }
29536 }
29537
29538 void FFScript::do_file_geterr()
29539 {
29540 if(user_file* f = checkFile(ri->fileref, true))
29541 {
29542 int32_t err = ferror(f->file);
29543 int32_t arrayptr = get_register(sarg1);
29544 if(err)
29545 {
29546 string error = strerror(err);
29547 ArrayH::setArray(arrayptr, error);
29548 }
29549 else
29550 {
29551 ArrayH::setArray(arrayptr, "\0");
29552 }
29553 }
29554 }
29555 ///----------------------------------------------------------------------------------------------------
29556 //Directory
29557
29558 void FFScript::do_directory_get()
29559 {
29560 if(user_dir* dr = checkDir(ri->directoryref, true))
29561 {
29562 int32_t indx = get_register(sarg1) / 10000L;
29563 int32_t arrayptr = get_register(sarg2);
29564 char buf[2048] = {0};
29565 set_register(sarg1, dr->get(indx, buf) ? 10000L : 0L);
29566 if(ArrayH::setArray(arrayptr, string(buf)) == SH::_Overflow)
29567 scripting_log_error_with_context("Array is not large enough");
29568 }
29569 else set_register(sarg1, 0L);
29570 }
29571
29572 void FFScript::do_directory_reload()
29573 {
29574 if(user_dir* dr = checkDir(ri->directoryref, true))
29575 {
29576 dr->refresh();
29577 }
29578 }
29579
29580 void FFScript::do_directory_free()
29581 {
29582 if(user_dir* dr = checkDir(ri->directoryref, true))
29583 {
29584 free_script_object(dr->id);
29585 }
29586 }
29587
29588 ///----------------------------------------------------------------------------------------------------
29589
29590 void FFScript::set_sarg1(int32_t v)
29591 {
29592 set_register(sarg1, v);
29593 }
29594
29595 5 void FFScript::do_isvalidbitmap()
29596 {
29597 5 int32_t id = get_register(sarg1);
29598
29599
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (id >= 0)
29600 {
29601 5 auto bmp = user_bitmaps.check(id, true);
29602
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
5 if (bmp && bmp->u_bmp)
29603 {
29604 set_register(sarg1, 10000);
29605 return;
29606 }
29607 5 }
29608
29609 5 set_register(sarg1, 0);
29610 5 }
29611 43 void FFScript::do_isallocatedbitmap()
29612 {
29613 43 int32_t id = get_register(sarg1);
29614
29615
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 if (id >= 0)
29616 {
29617 43 auto bmp = user_bitmaps.check(id, true);
29618
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 42 times.
43 if (bmp)
29619 {
29620 42 set_register(sarg1, 10000);
29621 42 return;
29622 }
29623 1 }
29624
29625 1 set_register(sarg1, 0);
29626 43 }
29627
29628 417 void FFScript::user_bitmaps_init()
29629 {
29630 417 user_bitmaps.clear();
29631 417 }
29632
29633 3858 int32_t FFScript::do_create_bitmap()
29634 {
29635 3858 int32_t w = (ri->d[rINDEX2] / 10000);
29636 3858 int32_t h = (ri->d[rINDEX]/10000);
29637
1/2
✓ Branch 0 taken 3858 times.
✗ Branch 1 not taken.
3858 if ( get_qr(qr_OLDCREATEBITMAP_ARGS) )
29638 {
29639 std::swap(w, h);
29640 }
29641
29642 3858 return create_user_bitmap_ex(h,w);
29643 }
29644
29645 3858 uint32_t FFScript::create_user_bitmap_ex(int32_t w, int32_t h)
29646 {
29647 3858 auto bmp = user_bitmaps.create();
29648
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3858 times.
3858 if (!bmp)
29649 return 0;
29650
29651 3858 bmp->width = w;
29652 3858 bmp->height = h;
29653 3858 bmp->u_bmp = create_bitmap_ex(8,w,h);
29654 3858 clear_bitmap(bmp->u_bmp);
29655 3858 return bmp->id;
29656 3858 }
29657
29658 1800 bool FFScript::doesResolveToScreenBitmap(int32_t bitmap_id)
29659 {
29660
2/2
✓ Branch 0 taken 1440 times.
✓ Branch 1 taken 360 times.
1800 if (bitmap_id == rtSCREEN)
29661 360 return true;
29662
29663
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1440 times.
1440 if (bitmap_id == -2)
29664 {
29665 int curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
29666 if (curr_rt >= 0 && curr_rt < 7)
29667 return false;
29668
29669 return true;
29670 }
29671
29672 1440 return false;
29673 1800 }
29674
29675 1800 bool FFScript::doesResolveToDeprecatedSystemBitmap(int32_t bitmap_id)
29676 {
29677
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1800 times.
1800 switch (bitmap_id)
29678 {
29679 case rtBMP0:
29680 case rtBMP1:
29681 case rtBMP2:
29682 case rtBMP3:
29683 case rtBMP4:
29684 case rtBMP5:
29685 case rtBMP6:
29686 {
29687 return true;
29688 }
29689 }
29690
29691
1/2
✓ Branch 0 taken 1800 times.
✗ Branch 1 not taken.
1800 if (bitmap_id == -2)
29692 {
29693 int curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
29694 if (curr_rt >= 0 && curr_rt < 7)
29695 return true;
29696 }
29697
29698 1800 return false;
29699 1800 }
29700
29701 53694974 BITMAP* FFScript::GetScriptBitmap(int32_t id, BITMAP* screen_bmp, bool skipError)
29702 {
29703
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 53694494 times.
✓ Branch 2 taken 480 times.
53694974 switch (id - 10)
29704 {
29705 case rtSCREEN:
29706 480 return screen_bmp;
29707
29708 case rtBMP0:
29709 case rtBMP1:
29710 case rtBMP2:
29711 case rtBMP3:
29712 case rtBMP4:
29713 case rtBMP5:
29714 case rtBMP6: //old system bitmaps (render targets)
29715 {
29716 return zscriptDrawingRenderTarget->GetBitmapPtr(id - 10);
29717 }
29718 }
29719
29720
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53694494 times.
53694494 if (auto bitmap = checkBitmap(id, true, skipError))
29721 53694494 return bitmap->u_bmp;
29722
29723 return nullptr;
29724 53694974 }
29725
29726 225 uint32_t FFScript::get_free_bitmap(bool skipError)
29727 {
29728 225 auto bmp = user_bitmaps.create(skipError);
29729
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 225 times.
225 if (!bmp)
29730 return 0;
29731 225 return bmp->id;
29732 225 }
29733
29734 3512 void FFScript::do_deallocate_bitmap()
29735 {
29736
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3512 times.
3512 if (ZScriptVersion::gc())
29737 return;
29738
29739
1/2
✓ Branch 0 taken 3512 times.
✗ Branch 1 not taken.
3512 if(isSystemBitref(ri->bitmapref))
29740 {
29741 return; //Don't attempt to deallocate system bitmaps!
29742 }
29743
29744 // Bitmaps are not deallocated right away, but deferred until the next call to scb.update()
29745
1/2
✓ Branch 0 taken 3512 times.
✗ Branch 1 not taken.
3512 if (auto b = checkBitmap(ri->bitmapref, false, true))
29746 3512 b->free_obj();
29747 3512 }
29748
29749 3658 bool FFScript::isSystemBitref(int32_t ref)
29750 {
29751
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 switch(ref-10)
29752 {
29753 case rtSCREEN:
29754 case rtBMP0:
29755 case rtBMP1:
29756 case rtBMP2:
29757 case rtBMP3:
29758 case rtBMP4:
29759 case rtBMP5:
29760 case rtBMP6:
29761 return true;
29762 }
29763 3658 return false;
29764 3658 }
29765
29766 ///----------------------------------------------------------------------------------------------------
29767
29768 1661 int32_t FFScript::GetQuestVersion()
29769 {
29770 1661 return QHeader.zelda_version;
29771 }
29772 729 int32_t FFScript::GetQuestBuild()
29773 {
29774 729 return QHeader.build;
29775 }
29776 int32_t FFScript::GetQuestSectionVersion(int32_t section)
29777 {
29778 return QHeader.zelda_version;
29779 }
29780
29781 19 int32_t FFScript::GetDefaultWeaponSprite(int32_t wpn_id)
29782 {
29783
2/63
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✓ Branch 49 taken 10 times.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
19 switch (wpn_id)
29784 {
29785 case wNone:
29786 return 0;
29787
29788 case wSword: return 0;
29789 case wBeam: return 1;
29790 case wBrang: return 4;
29791 case wBomb: return 9;
29792 case wSBomb: return 75;
29793 case wLitBomb: return 7;
29794 case wLitSBomb: return 8;
29795 case wArrow: return 10;
29796 case wRefArrow: return 10;
29797 case wFire: return 12;
29798 case wRefFire: return 12;
29799 case wRefFire2: return 12;
29800 case wWhistle: return 45; //blank, unused misc sprite
29801 case wBait: return 14;
29802 case wWand: return 15;
29803 case wMagic: return 16;
29804 case wCatching: return 45; //blank, unused misc sprite
29805 case wWind: return 13;
29806 case wRefMagic: return 16;
29807 case wRefFireball: return 17;
29808 case wRefRock: return 18;
29809 case wHammer: return 25;
29810 case wHookshot: return 26;
29811 case wHSHandle: return 28;
29812 case wHSChain: return 27;
29813 case wSSparkle: return 29;
29814 case wFSparkle: return 32;
29815 case wSmack: return 33;
29816 case wPhantom: return -1;
29817 case wCByrna: return 87;
29818 case wRefBeam: return 1;
29819 case wStomp: return 45; //blank, unused misc sprite
29820 case lwMax: return 45; //blank, unused misc sprite
29821 case wScript1: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 246; else return 0; }
29822 case wScript2: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 247; else return 0; }
29823 case wScript3: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 248; else return 0; }
29824 case wScript4: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 249; else return 0; }
29825 case wScript5: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 250; else return 0; }
29826 case wScript6: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 251; else return 0; }
29827 case wScript7: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 252; else return 0; }
29828 case wScript8: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 253; else return 0; }
29829 case wScript9: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 254; else return 0; }
29830 case wScript10: { if ( get_qr(qr_WRITING_NPC_WEAPON_UNIQUE_SPRITES ) ) return 255; else return 0; }
29831
29832 case wIce: return 83;
29833 //Cannot use any of these weapons yet.
29834 //return -1;
29835
29836 case wEnemyWeapons:
29837 9 case ewFireball: return 17;
29838
29839 case ewArrow: return 19;
29840 case ewBrang: return 4;
29841 10 case ewSword: return 20;
29842 case ewRock: return 18;
29843 case ewMagic: return 21;
29844 case ewBomb: return 78;
29845 case ewSBomb: return 79;
29846 case ewLitBomb: return 76;
29847 case ewLitSBomb: return 77;
29848 case ewFireTrail: return 80;
29849 case ewFlame: return 35;
29850 case ewWind: return 36;
29851 case ewFlame2: return 81;
29852 case ewFlame2Trail: return 82;
29853 case ewIce: return 83;
29854 case ewFireball2: return 17; //fireball (rising)
29855
29856
29857 default: return -1; //No assign.
29858
29859 }
29860 19 }
29861
29862 19 int32_t FFScript::GetDefaultWeaponSFX(int32_t wpn_id)
29863 {
29864
2/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
19 switch (wpn_id)
29865 {
29866 case ewFireTrail:
29867 case ewFlame:
29868 case ewFlame2Trail:
29869 case ewFlame2:
29870 return WAV_FIRE; break;
29871 case ewWind:
29872 case ewMagic:
29873 return WAV_WAND; break;
29874 case ewIce:
29875 return WAV_ZN1ICE; break;
29876 case ewRock:
29877 return WAV_ZN1ROCK; break;
29878 case ewFireball2:
29879 case ewFireball:
29880 9 return WAV_ZN1FIREBALL; break;
29881 }
29882 10 return -1; //no assign
29883 19 }
29884
29885 //bitmap->GetPixel()
29886
29887
29888 int32_t FFScript::do_getpixel()
29889 {
29890 int32_t xoffset = 0, yoffset = 0;
29891 int32_t xoff = 0; int32_t yoff = 0;
29892 const bool brokenOffset= ( (get_er(er_BITMAPOFFSET)!=0)
29893 || (get_qr(qr_BITMAPOFFSETFIX)!=0) );
29894
29895 BITMAP *bitty = FFCore.GetScriptBitmap(ri->bitmapref, screen);
29896 if(!bitty)
29897 {
29898 bitty = scrollbuf;
29899 }
29900 // draw to screen with subscreen offset
29901 if(!brokenOffset && ri->bitmapref == rtSCREEN + 10 )
29902 {
29903 xoffset = xoff;
29904 yoffset = 56; //should this be -56?
29905 }
29906 else
29907 {
29908 xoffset = 0;
29909 yoffset = 0;
29910 }
29911
29912 int32_t yv = ri->d[rINDEX2]/10000 + yoffset;
29913 int32_t ret = getpixel(bitty, ri->d[rINDEX]/10000, yv); //This is a palette index value.
29914 if(!get_qr(qr_BROKEN_GETPIXEL_VALUE))
29915 ret *= 10000;
29916 return ret;
29917 }
29918
29919 void FFScript::do_bmpcollision()
29920 {
29921 int32_t bmpref = SH::read_stack(ri->sp + 5);
29922 int32_t maskbmpref = SH::read_stack(ri->sp + 4);
29923 int32_t x = SH::read_stack(ri->sp + 3) / 10000;
29924 int32_t y = SH::read_stack(ri->sp + 2) / 10000;
29925 int32_t checkCol = SH::read_stack(ri->sp + 1) / 10000;
29926 int32_t maskCol = SH::read_stack(ri->sp + 0) / 10000;
29927 BITMAP *checkbit = FFCore.GetScriptBitmap(bmpref, screen, true);
29928 BITMAP *maskbit = FFCore.GetScriptBitmap(maskbmpref, screen, true);
29929 if(!(checkbit && maskbit))
29930 {
29931 set_register(sarg1, -10000);
29932 char buf1[16];
29933 char buf2[16];
29934 zc_itoa(bmpref, buf1);
29935 zc_itoa(maskbmpref, buf2);
29936 Z_scripterrlog("Invalid bitmap%s passed to 'bitmap->CountColor()': %s%s%s\n",
29937 (checkbit || maskbit) ? "" : "s", checkbit ? "" : buf1,
29938 (checkbit || maskbit) ? "" : ", ", maskbit ? "" : buf2);
29939 return;
29940 }
29941 int32_t ret = countColor(checkbit, maskbit, x, y, checkCol, maskCol);
29942 set_register(sarg1, ret*10000);
29943 }
29944
29945
29946 6567172 int32_t FFScript::loadMapData()
29947 {
29948 6567172 int32_t map = (ri->d[rINDEX] / 10000);
29949 6567172 int32_t screen = (ri->d[rINDEX2]/10000);
29950
1/2
✓ Branch 0 taken 6567172 times.
✗ Branch 1 not taken.
6567172 int32_t indx = (zc_max((map)-1,0) * MAPSCRS + screen);
29951
2/4
✓ Branch 0 taken 6567172 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6567172 times.
6567172 if ( map < 1 || map > map_count )
29952 {
29953 Z_scripterrlog("Invalid Map ID passed to Game->LoadMapData: %d\n", map);
29954 ri->mapsref = MAX_SIGNED_32;
29955 }
29956
2/4
✓ Branch 0 taken 6567172 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6567172 times.
6567172 else if ( screen < 0 || screen > 129 ) //0x00 to 0x81 -Z
29957 {
29958 Z_scripterrlog("Invalid Screen Index passed to Game->LoadMapData: %d\n", screen);
29959 ri->mapsref = MAX_SIGNED_32;
29960 }
29961 6567172 else ri->mapsref = indx;
29962 6567172 return ri->mapsref;
29963 }
29964
29965 // Called when leaving a screen; deallocate arrays created by FFCs that aren't carried over
29966 13690337 void FFScript::deallocateArray(int32_t ptrval)
29967 {
29968
1/2
✓ Branch 0 taken 13690337 times.
✗ Branch 1 not taken.
13690337 CHECK(!ZScriptVersion::gc_arrays());
29969
29970
1/2
✓ Branch 0 taken 13690337 times.
✗ Branch 1 not taken.
13690337 if(ptrval == 0)
29971 return;
29972
2/4
✓ Branch 0 taken 13690337 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 13690337 times.
13690337 if(ptrval==0 || ptrval >= NUM_ZSCRIPT_ARRAYS)
29973 scripting_log_error_with_context("Script tried to deallocate memory at invalid address {}", ptrval);
29974
1/2
✓ Branch 0 taken 13690337 times.
✗ Branch 1 not taken.
13690337 else if(ptrval<0)
29975 scripting_log_error_with_context("Script tried to deallocate memory at object-based address {}", ptrval);
29976 else
29977 {
29978
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13690337 times.
13690337 if(arrayOwner[ptrval].specOwned) return; //ignore this deallocation
29979
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13690337 times.
13690337 if(arrayOwner[ptrval].specCleared) return;
29980 13690337 arrayOwner[ptrval].clear();
29981
29982
1/2
✓ Branch 0 taken 13690337 times.
✗ Branch 1 not taken.
13690337 if(!localRAM[ptrval].Valid())
29983 scripting_log_error_with_context("Script tried to deallocate memory that was not allocated at address {}", ptrval);
29984 else
29985 {
29986
2/2
✓ Branch 0 taken 13690334 times.
✓ Branch 1 taken 3 times.
13690337 if (localRAM[ptrval].HoldsObjects())
29987 {
29988 3 auto&& aptr = localRAM[ptrval];
29989
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 for (int i = 0; i < aptr.Size(); i++)
29990 {
29991 2 int id = aptr[i];
29992 2 script_object_ref_dec(id);
29993 2 }
29994 3 }
29995 13690337 localRAM[ptrval].Clear();
29996 }
29997 }
29998 13690337 }
29999
30000 2617631 int32_t FFScript::get_screen_d(int32_t index1, int32_t index2)
30001 {
30002
3/4
✓ Branch 0 taken 2617631 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 2617625 times.
2617631 if(index2 < 0 || index2 > 7)
30003 {
30004 6 Z_scripterrlog("You were trying to reference an out-of-bounds array index for a screen's D[] array (%ld); valid indices are from 0 to 7.\n", index1);
30005 6 return 0;
30006 }
30007
2/4
✓ Branch 0 taken 2617625 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2617625 times.
2617625 if (index1 < 0 || index1 >= game->screen_d.size())
30008 {
30009 Z_scripterrlog("You were trying to reference an out-of-bounds screen for a D[] array (%ld); valid indices are from 0 to %ld.\n", index1, game->screen_d.size() - 1);
30010 return 0;
30011 }
30012
30013 2617625 return game->screen_d[index1][index2];
30014 2617631 }
30015
30016 54370 void FFScript::set_screen_d(int32_t index1, int32_t index2, int32_t val)
30017 {
30018
2/4
✓ Branch 0 taken 54370 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 54370 times.
54370 if(index2 < 0 || index2 > 7)
30019 {
30020 Z_scripterrlog("You were trying to reference an out-of-bounds array index for a screen's D[] array (%ld); valid indices are from 0 to 7.\n", index1);
30021 return;
30022 }
30023
2/4
✓ Branch 0 taken 54370 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 54370 times.
54370 if (index1 < 0 || index1 >= game->screen_d.size())
30024 {
30025 Z_scripterrlog("You were trying to reference an out-of-bounds screen for a D[] array (%ld); valid indices are from 0 to %ld.\n", index1, game->screen_d.size() - 1);
30026 return;
30027 }
30028
30029 54370 game->screen_d[index1][index2] = val;
30030 54370 }
30031
30032 void FFScript::do_zapout()
30033 {
30034 zapout();
30035 }
30036
30037 void FFScript::do_zapin(){ zapin(); }
30038
30039 void FFScript::do_openscreen() { openscreen(); }
30040 void FFScript::do_closescreen() { closescreen(); }
30041 void FFScript::do_openscreenshape()
30042 {
30043 int32_t shape = get_register(sarg1) / 10000;
30044 if(shape < 0 || shape >= bosMAX)
30045 {
30046 Z_scripterrlog("Invalid shape passed to %s! Valid range %d to %d. Using 'Circle' shape.\n", "Screen->OpeningWipe(int32_t)", 0, bosMAX-1);
30047 shape = bosCIRCLE;
30048 }
30049 openscreen(shape);
30050 }
30051 void FFScript::do_closescreenshape()
30052 {
30053 int32_t shape = get_register(sarg1) / 10000;
30054 if(shape < 0 || shape >= bosMAX)
30055 {
30056 Z_scripterrlog("Invalid shape passed to %s! Valid range %d to %d. Using 'Circle' shape.\n", "Screen->ClosingWipe(int32_t)", 0, bosMAX-1);
30057 shape = bosCIRCLE;
30058 }
30059 closescreen(shape);
30060 }
30061 void FFScript::do_wavyin() { wavyin(); }
30062 void FFScript::do_wavyout() { wavyout(false); }
30063
30064
30065 void FFScript::do_triggersecret(const bool v)
30066 {
30067 int32_t ID = vbound((SH::get_arg(sarg1, v) / 10000), 0, 255);
30068 mapscr *s = hero_scr;
30069 //Convert a flag type to a secret type.
30070 int32_t ft = combo_trigger_flag_to_secret_combo_index(ID);
30071 if (ft != -1)
30072 {
30073 for(int32_t iter=0; iter<2; ++iter)
30074 {
30075 for ( int32_t q = 0; q < 176; q++ )
30076 {
30077 //Placed flags
30078 if ( iter == 1 )
30079 {
30080 if ( s->sflag[q] == ID ) {
30081 auto rpos_handle = get_rpos_handle_for_screen(s->screen, 0, q);
30082 screen_combo_modify_preroutine(rpos_handle);
30083 s->data[q] = s->secretcombo[ft];
30084 s->cset[q] = s->secretcset[ft];
30085 s->sflag[q] = s->secretflag[ft];
30086 screen_combo_modify_postroutine(rpos_handle);
30087 }
30088 }
30089 //Inherent flags
30090 else
30091 {
30092 if ( combobuf[s->data[q]].flag == ID ) {
30093 auto rpos_handle = get_rpos_handle_for_screen(s->screen, 0, q);
30094 screen_combo_modify_preroutine(rpos_handle);
30095 s->data[q] = s->secretcombo[ft];
30096 s->cset[q] = s->secretcset[ft];
30097 screen_combo_modify_postroutine(rpos_handle);
30098 }
30099
30100 }
30101 }
30102 }
30103 }
30104
30105 }
30106 //NPCData
30107
30108 //NPCData Getter Macros
30109
30110
30111
30112
30113 //NPCData-> Function
30114 #define GET_NPCDATA_FUNCTION_VAR_INT(member) \
30115 { \
30116 int32_t ID = get_register(sarg2) / 10000; \
30117 if(ID < 1 || ID > (MAXGUYS-1)) \
30118 set_register(sarg1, -10000); \
30119 else \
30120 set_register(sarg1, guysbuf[ID].member * 10000); \
30121 }
30122
30123 #define GET_NPCDATA_FUNCTION_VAR_INDEX(member, indexbound) \
30124 { \
30125 int32_t ID = int32_t(ri->d[rINDEX] / 10000);\
30126 int32_t indx = vbound((ri->d[rINDEX2] / 10000), 0, indexbound); \
30127 if(ID < 1 || ID > (MAXGUYS-1)) \
30128 set_register(sarg1, -10000); \
30129 else \
30130 set_register(sarg1, guysbuf[ID].member[indx] * 10000); \
30131 }
30132
30133 #define GET_NPCDATA_FUNCTION_VAR_FLAG(member) \
30134 { \
30135 int32_t ID = int32_t(ri->d[rINDEX] / 10000);\
30136 int32_t flag = int32_t(ri->d[rINDEX2] / 10000);\
30137 if(ID < 1 || ID > (MAXGUYS-1)) \
30138 set_register(sarg1, -10000); \
30139 else \
30140 set_register(sarg1, (guysbuf[ID].member&flag) ? 10000 : 0); \
30141 }
30142
30143 uint32_t get_upper_half_uint64(uint64_t value)
30144 {
30145 return value >> 32;
30146 }
30147
30148 uint32_t get_lower_half_uint64(uint64_t value)
30149 {
30150 return value & 0xFFFFFFFF;
30151 }
30152
30153 // Defunct.
30154 void FFScript::getNPCData_flags(){
30155 int32_t ID = get_register(sarg2) / 10000;
30156 if(ID < 1 || ID > (MAXGUYS-1))
30157 set_register(sarg1, -10000);
30158 else
30159 set_register(sarg1, get_upper_half_uint64(guysbuf[ID].flags) * 10000);
30160 }
30161
30162 // Defunct.
30163 void FFScript::getNPCData_flags2(){
30164 int32_t ID = get_register(sarg2) / 10000;
30165 if(ID < 1 || ID > (MAXGUYS-1))
30166 set_register(sarg1, -10000);
30167 else
30168 set_register(sarg1, get_lower_half_uint64(guysbuf[ID].flags) * 10000);
30169 }
30170
30171 void FFScript::getNPCData_tile() { GET_NPCDATA_FUNCTION_VAR_INT(tile); }
30172 void FFScript::getNPCData_width(){ GET_NPCDATA_FUNCTION_VAR_INT(width); }
30173 void FFScript::getNPCData_height(){ GET_NPCDATA_FUNCTION_VAR_INT(height); }
30174 void FFScript::getNPCData_s_tile(){ GET_NPCDATA_FUNCTION_VAR_INT(s_tile); }
30175 void FFScript::getNPCData_s_width(){ GET_NPCDATA_FUNCTION_VAR_INT(s_width); }
30176 void FFScript::getNPCData_s_height(){ GET_NPCDATA_FUNCTION_VAR_INT(s_height); }
30177 void FFScript::getNPCData_e_tile(){ GET_NPCDATA_FUNCTION_VAR_INT(e_tile); }
30178 void FFScript::getNPCData_e_width(){ GET_NPCDATA_FUNCTION_VAR_INT(e_width); }
30179 void FFScript::getNPCData_e_height() { GET_NPCDATA_FUNCTION_VAR_INT(e_height); }
30180 void FFScript::getNPCData_hp(){ GET_NPCDATA_FUNCTION_VAR_INT(hp); }
30181 void FFScript::getNPCData_family(){ GET_NPCDATA_FUNCTION_VAR_INT(family); }
30182 void FFScript::getNPCData_cset(){ GET_NPCDATA_FUNCTION_VAR_INT(cset); }
30183 void FFScript::getNPCData_anim(){ GET_NPCDATA_FUNCTION_VAR_INT(anim); }
30184 void FFScript::getNPCData_e_anim(){ GET_NPCDATA_FUNCTION_VAR_INT(e_anim); }
30185 void FFScript::getNPCData_frate(){ GET_NPCDATA_FUNCTION_VAR_INT(frate); }
30186 void FFScript::getNPCData_e_frate(){ GET_NPCDATA_FUNCTION_VAR_INT(e_frate); }
30187 void FFScript::getNPCData_dp(){ GET_NPCDATA_FUNCTION_VAR_INT(dp); }
30188 void FFScript::getNPCData_wdp(){ GET_NPCDATA_FUNCTION_VAR_INT(wdp); }
30189 void FFScript::getNPCData_weapon(){ GET_NPCDATA_FUNCTION_VAR_INT(weapon); }
30190 void FFScript::getNPCData_rate(){ GET_NPCDATA_FUNCTION_VAR_INT(rate); }
30191 void FFScript::getNPCData_hrate(){ GET_NPCDATA_FUNCTION_VAR_INT(hrate); }
30192 void FFScript::getNPCData_step(){ GET_NPCDATA_FUNCTION_VAR_INT(step); }
30193 void FFScript::getNPCData_homing(){ GET_NPCDATA_FUNCTION_VAR_INT(homing); }
30194 void FFScript::getNPCData_grumble(){ GET_NPCDATA_FUNCTION_VAR_INT(grumble); }
30195 void FFScript::getNPCData_item_set(){ GET_NPCDATA_FUNCTION_VAR_INT(item_set); }
30196 void FFScript::getNPCData_bgsfx(){ GET_NPCDATA_FUNCTION_VAR_INT(bgsfx); }
30197 void FFScript::getNPCData_hitsfx(){ GET_NPCDATA_FUNCTION_VAR_INT(hitsfx); }
30198 void FFScript::getNPCData_deadsfx(){ GET_NPCDATA_FUNCTION_VAR_INT(deadsfx); }
30199 void FFScript::getNPCData_xofs(){ GET_NPCDATA_FUNCTION_VAR_INT(xofs); }
30200 void FFScript::getNPCData_yofs(){ GET_NPCDATA_FUNCTION_VAR_INT(yofs); }
30201 void FFScript::getNPCData_zofs(){ GET_NPCDATA_FUNCTION_VAR_INT(zofs); }
30202 void FFScript::getNPCData_hxofs(){ GET_NPCDATA_FUNCTION_VAR_INT(hxofs); }
30203 void FFScript::getNPCData_hyofs(){ GET_NPCDATA_FUNCTION_VAR_INT(hyofs); }
30204 void FFScript::getNPCData_hxsz(){ GET_NPCDATA_FUNCTION_VAR_INT(hxsz); }
30205 void FFScript::getNPCData_hysz(){ GET_NPCDATA_FUNCTION_VAR_INT(hysz); }
30206 void FFScript::getNPCData_hzsz(){ GET_NPCDATA_FUNCTION_VAR_INT(hzsz); }
30207 void FFScript::getNPCData_txsz(){ GET_NPCDATA_FUNCTION_VAR_INT(txsz); }
30208 void FFScript::getNPCData_tysz(){ GET_NPCDATA_FUNCTION_VAR_INT(tysz); }
30209 void FFScript::getNPCData_wpnsprite(){ GET_NPCDATA_FUNCTION_VAR_INT(wpnsprite); }
30210 void FFScript::getNPCData_firesfx() { GET_NPCDATA_FUNCTION_VAR_INT(firesfx); }
30211
30212
30213 void FFScript::getNPCData_defense(){GET_NPCDATA_FUNCTION_VAR_INDEX(defense,int32_t(edefLAST255))};
30214
30215
30216 void FFScript::getNPCData_SIZEflags(){GET_NPCDATA_FUNCTION_VAR_FLAG(SIZEflags);}
30217
30218
30219 void FFScript::getNPCData_misc()
30220 {
30221 int32_t ID = int32_t(ri->d[rINDEX] / 10000); //the enemy ID value
30222 int32_t indx = int32_t(ri->d[rINDEX2] / 10000); //the misc index ID
30223 if ((ID < 1 || ID > 511) || ( indx < 0 || indx >= MAX_NPC_ATTRIBUTES ))
30224 set_register(sarg1, -10000);
30225 else set_register(sarg1, guysbuf[ID].attributes[indx] * 10000);
30226 }
30227
30228 //NPCData Setters, two inputs, no return; similar to void GetDMapIntro(int32_t DMap, int32_t buffer[]);
30229
30230 //NPCData Setter Macros
30231
30232 //Variables for spritedata sp->member
30233
30234
30235
30236 //Functions for NPCData->
30237
30238 #define SET_NPCDATA_FUNCTION_VAR_INT(member, bound) \
30239 { \
30240 int32_t ID = get_register(sarg1) / 10000; \
30241 int32_t val = get_register(sarg2) / 10000; \
30242 if(ID < 1 || ID > (MAXGUYS-1)) \
30243 set_register(sarg1, -10000); \
30244 else \
30245 guysbuf[ID].member = vbound(val,0,bound); \
30246 }
30247
30248 #define SET_NPCDATA_FUNCTION_VAR_ENUM(member, bound) \
30249 { \
30250 int32_t ID = get_register(sarg1) / 10000; \
30251 int32_t val = get_register(sarg2) / 10000; \
30252 if(ID < 1 || ID > (MAXGUYS-1)) \
30253 set_register(sarg1, -10000); \
30254 else \
30255 guysbuf[ID].member = (decltype(guysbuf[ID].member))vbound(val,0,bound); \
30256 }
30257
30258
30259 #define SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(member) \
30260 { \
30261 int32_t ID = get_register(sarg1) / 10000; \
30262 int32_t val = get_register(sarg2) / 10000; \
30263 if(ID < 1 || ID > (MAXGUYS-1)) \
30264 set_register(sarg1, -10000); \
30265 else \
30266 guysbuf[ID].member = val; \
30267 }
30268
30269
30270 //SET_NPC_VAR_INDEX(member,value)
30271 #define SET_NPCDATA_FUNCTION_VAR_INDEX(member, val, bound, indexbound) \
30272 { \
30273 int32_t ID = (ri->d[rINDEX]/10000); \
30274 int32_t indx = vbound((ri->d[rINDEX2]/10000),0,indexbound); \
30275 if(ID < 1 || ID > (MAXGUYS-1)) \
30276 return; \
30277 else \
30278 guysbuf[ID].member[indx] = vbound(val,0,bound); \
30279 }
30280
30281 //Special case for flags, three inputs one return
30282 #define SET_NPCDATA_FUNCTION_VAR_FLAG(member, val) \
30283 { \
30284 int32_t ID = (ri->d[rINDEX]/10000); \
30285 int32_t flag = (ri->d[rINDEX2]/10000); \
30286 if(ID < 1 || ID > (MAXGUYS-1)) \
30287 return; \
30288 else \
30289 { \
30290 if ( val != 0 ) guysbuf[ID].member|=flag; \
30291 else guysbuf[ID].member|= ~flag; \
30292 }\
30293 }
30294
30295 static uint64_t set_upper_half_uint64(uint64_t num, uint32_t half)
30296 {
30297 uint64_t lower = num & 0x00000000FFFFFFFF;
30298 return lower | ((uint64_t)half << 32);
30299 }
30300
30301 static uint64_t set_lower_half_uint64(uint64_t num, uint32_t half)
30302 {
30303 uint64_t upper = num & 0xFFFFFFFF00000000;
30304 return upper | half;
30305 }
30306
30307 // Defunct.
30308 void FFScript::setNPCData_flags(){
30309 int32_t ID = get_register(sarg1) / 10000;
30310 int32_t val = get_register(sarg2) / 10000;
30311 if(ID < 1 || ID > (MAXGUYS-1))
30312 set_register(sarg1, -10000);
30313 else
30314 {
30315 guysbuf[ID].flags = (guy_flags)set_upper_half_uint64(guysbuf[ID].flags, vbound(val, 0, 0x7FFFFFFF));
30316 }
30317 }
30318
30319 // Defunct.
30320 void FFScript::setNPCData_flags2(){
30321 int32_t ID = get_register(sarg1) / 10000;
30322 int32_t val = get_register(sarg2) / 10000;
30323 if(ID < 1 || ID > (MAXGUYS-1))
30324 set_register(sarg1, -10000);
30325 else
30326 {
30327 guysbuf[ID].flags = (guy_flags)set_lower_half_uint64(guysbuf[ID].flags, vbound(val, 0, 0x7FFFFFFF));
30328 }
30329 }
30330 void FFScript::setNPCData_tile() { SET_NPCDATA_FUNCTION_VAR_INT(tile, ZS_WORD); }
30331 void FFScript::setNPCData_width(){SET_NPCDATA_FUNCTION_VAR_INT(width,ZS_BYTE);}
30332 void FFScript::setNPCData_height(){SET_NPCDATA_FUNCTION_VAR_INT(height,ZS_BYTE);}
30333 void FFScript::setNPCData_s_tile(){SET_NPCDATA_FUNCTION_VAR_INT(s_tile,ZS_WORD);}
30334 void FFScript::setNPCData_s_width(){SET_NPCDATA_FUNCTION_VAR_INT(s_width,ZS_BYTE);}
30335 void FFScript::setNPCData_s_height(){SET_NPCDATA_FUNCTION_VAR_INT(s_height,ZS_BYTE);}
30336 void FFScript::setNPCData_e_tile(){SET_NPCDATA_FUNCTION_VAR_INT(e_tile,ZS_WORD);}
30337 void FFScript::setNPCData_e_width(){SET_NPCDATA_FUNCTION_VAR_INT(e_width,ZS_BYTE);}
30338 void FFScript::setNPCData_e_height() { SET_NPCDATA_FUNCTION_VAR_INT(e_height, ZS_BYTE); }
30339 void FFScript::setNPCData_hp(){SET_NPCDATA_FUNCTION_VAR_INT(hp,ZS_SHORT);}
30340 void FFScript::setNPCData_family(){SET_NPCDATA_FUNCTION_VAR_INT(family,ZS_SHORT);}
30341 void FFScript::setNPCData_cset(){SET_NPCDATA_FUNCTION_VAR_INT(cset,ZS_SHORT);}
30342 void FFScript::setNPCData_anim(){SET_NPCDATA_FUNCTION_VAR_INT(anim,ZS_SHORT);}
30343 void FFScript::setNPCData_e_anim(){SET_NPCDATA_FUNCTION_VAR_INT(e_anim,ZS_SHORT);}
30344 void FFScript::setNPCData_frate(){SET_NPCDATA_FUNCTION_VAR_INT(frate,ZS_SHORT);}
30345 void FFScript::setNPCData_e_frate(){SET_NPCDATA_FUNCTION_VAR_INT(e_frate,ZS_SHORT);}
30346 void FFScript::setNPCData_dp(){SET_NPCDATA_FUNCTION_VAR_INT(dp,ZS_SHORT);}
30347 void FFScript::setNPCData_wdp(){SET_NPCDATA_FUNCTION_VAR_INT(wdp,ZS_SHORT);}
30348 void FFScript::setNPCData_weapon(){SET_NPCDATA_FUNCTION_VAR_INT(weapon,ZS_SHORT);}
30349 void FFScript::setNPCData_rate(){SET_NPCDATA_FUNCTION_VAR_INT(rate,ZS_SHORT);}
30350 void FFScript::setNPCData_hrate(){SET_NPCDATA_FUNCTION_VAR_INT(hrate,ZS_SHORT);}
30351 void FFScript::setNPCData_step(){SET_NPCDATA_FUNCTION_VAR_INT(step,ZS_SHORT);}
30352 void FFScript::setNPCData_homing(){SET_NPCDATA_FUNCTION_VAR_INT(homing,ZS_SHORT);}
30353 void FFScript::setNPCData_grumble(){SET_NPCDATA_FUNCTION_VAR_INT(grumble,ZS_SHORT);}
30354 void FFScript::setNPCData_item_set(){SET_NPCDATA_FUNCTION_VAR_INT(item_set,ZS_SHORT);}
30355 void FFScript::setNPCData_bgsfx(){SET_NPCDATA_FUNCTION_VAR_INT(bgsfx,ZS_SHORT);}
30356 void FFScript::setNPCData_hitsfx(){SET_NPCDATA_FUNCTION_VAR_INT(hitsfx,ZS_BYTE);}
30357 void FFScript::setNPCData_deadsfx(){SET_NPCDATA_FUNCTION_VAR_INT(deadsfx,ZS_BYTE);}
30358 void FFScript::setNPCData_xofs(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(xofs);}
30359 void FFScript::setNPCData_yofs(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(yofs);}
30360 void FFScript::setNPCData_zofs(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(zofs);}
30361 void FFScript::setNPCData_hxofs(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(hxofs);}
30362 void FFScript::setNPCData_hyofs(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(hyofs);}
30363 void FFScript::setNPCData_hxsz(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(hxsz);}
30364 void FFScript::setNPCData_hysz(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(hysz);}
30365 void FFScript::setNPCData_hzsz(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(hzsz);}
30366 void FFScript::setNPCData_txsz(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(txsz);}
30367 void FFScript::setNPCData_tysz(){SET_NPCDATA_FUNCTION_VAR_INT_NOBOUND(tysz);}
30368 void FFScript::setNPCData_wpnsprite(){SET_NPCDATA_FUNCTION_VAR_INT(wpnsprite,511);}
30369 void FFScript::setNPCData_firesfx() { SET_NPCDATA_FUNCTION_VAR_INT(firesfx, 255); }
30370
30371 //NPCData Setters, three inputs, no return. works as SetDMapScreenD function
30372
30373
30374
30375
30376
30377
30378
30379 void FFScript::setNPCData_defense(int32_t v){SET_NPCDATA_FUNCTION_VAR_INDEX(defense,v, ZS_INT, int32_t(edefLAST255) );}
30380 void FFScript::setNPCData_SIZEflags(int32_t v){SET_NPCDATA_FUNCTION_VAR_FLAG(SIZEflags,v);}
30381 void FFScript::setNPCData_misc(int32_t val)
30382 {
30383 int32_t ID = int32_t(ri->d[rINDEX] / 10000); //the enemy ID value
30384 int32_t indx = int32_t(ri->d[rINDEX2] / 10000); //the misc index ID
30385 if ((ID < 1 || ID > 511) || ( indx < 0 || indx >= MAX_NPC_ATTRIBUTES )) return;
30386 guysbuf[ID].attributes[indx] = val;
30387
30388 };
30389
30390 //ComboData
30391
30392 //Macros
30393
30394 //Are these right? newcombo is *combo_class_buf and the others are *combobuf
30395
30396 //Getters for ComboData 'Type' submembers.
30397 #define GET_COMBODATA_TYPE_INT(member) \
30398 { \
30399 int32_t ID = vbound((get_register(sarg2) / 10000),0,MAXCOMBOS);\
30400 set_register(sarg1, combo_class_buf[combobuf[ID].type].member * 10000); \
30401 }
30402
30403 //this may need additional macros.
30404 //for combo_class_buf[ID].member ?
30405 //I'm not sure which it needs to be at present.
30406
30407 #define GET_COMBODATA_TYPE_INDEX(member, bound) \
30408 { \
30409 int32_t ID = int32_t(vbound((ri->d[rINDEX] / 10000),0,MAXCOMBOS));\
30410 int32_t indx = int32_t(vbound((ri->d[rINDEX2] / 10000), 0, bound));\
30411 set_register(sarg1, combo_class_buf[combobuf[ID].type].member[indx] * 10000); \
30412 }
30413
30414 #define GET_COMBODATA_TYPE_FLAG(member) \
30415 { \
30416 int32_t ID = int32_t(vbound(ri->d[rINDEX] / 10000),0,MAXCOMBOS);\
30417 int32_t flag = int32_t(ri->d[rINDEX2] / 10000);\
30418 set_register(sarg1, (combo_class_buf[combobuf[ID].type].member&flag) ? 10000 : 0); \
30419 }
30420
30421
30422
30423 //Getters for ComboData main members.
30424 #define GET_COMBODATA_VAR_INT(member) \
30425 { \
30426 int32_t ID = vbound( (get_register(sarg2) / 10000), 0, MAXCOMBOS);\
30427 set_register(sarg1, combobuf[ID].member * 10000); \
30428 }
30429
30430 #define GET_COMBODATA_VAR_FLAG(member) \
30431 { \
30432 int32_t ID = int32_t( vbound( ( ri->d[rINDEX] / 10000),0,MAXCOMBOS) );\
30433 int32_t flag = int32_t(ri->d[rINDEX2] / 10000);\
30434 set_register(sarg1, (combobuf[ID].member&flag) ? 10000 : 0); \
30435 }
30436
30437
30438
30439 //ComboData Setter Macros
30440
30441 //Setters for ComboData 'type' submembers.
30442 #define SET_COMBODATA_TYPE_INT(member, bound) \
30443 { \
30444 int32_t ID = get_register(sarg1) / 10000; \
30445 int32_t val = vbound( (get_register(sarg2) / 10000), 0, bound); \
30446 if(ID < 1 || ID > 511) \
30447 set_register(sarg1, -10000); \
30448 else \
30449 combo_class_buf[combobuf[ID].type].member = val; \
30450 }
30451
30452 #define SET_COMBODATA_TYPE_INDEX(member, val, bound, indexbound) \
30453 { \
30454 int32_t ID = vbound((ri->d[rINDEX]/10000),0,MAXCOMBOS); \
30455 int32_t indx = vbound((ri->d[rINDEX2]/10000),0,indexbound); \
30456 combo_class_buf[combobuf[ID].type].member[indx] = vbound(val,0,bound); \
30457 }
30458
30459 #define SET_COMBODATA_TYPE_FLAG(member, val, bound) \
30460 { \
30461 int32_t ID = vbound((ri->d[rINDEX]/10000),0,MAXCOMBOS); \
30462 int32_t flag = (ri->d[rINDEX2]/10000); \
30463 combo_class_buf[combobuf[ID].type].member&flag = ((vbound(val,0,bound))!=0); \
30464 \
30465
30466
30467 //Setters for ComboData main members
30468 #define SET_COMBODATA_VAR_INT(member, bound) \
30469 { \
30470 int32_t ID = vbound( (get_register(sarg1) / 10000), 0, MAXCOMBOS); \
30471 int32_t val = vbound((get_register(sarg2) / 10000),0,bound); \
30472 screen_combo_modify_pre(ID); \
30473 combobuf[ID].member = val; \
30474 screen_combo_modify_post(ID); \
30475 }
30476
30477 //Getters
30478
30479 //one input, one return
30480 void FFScript::getComboData_block_enemies(){ GET_COMBODATA_TYPE_INT(block_enemies); } //byte a
30481 void FFScript::getComboData_block_hole(){ GET_COMBODATA_TYPE_INT(block_hole); } //byte b
30482 void FFScript::getComboData_block_trigger(){ GET_COMBODATA_TYPE_INT(block_trigger); } //byte c
30483 void FFScript::getComboData_conveyor_x_speed(){ GET_COMBODATA_TYPE_INT(conveyor_x_speed); } //int16_t e
30484 void FFScript::getComboData_conveyor_y_speed(){ GET_COMBODATA_TYPE_INT(conveyor_y_speed); } //int16_t f
30485 void FFScript::getComboData_create_enemy(){ GET_COMBODATA_TYPE_INT(create_enemy); } //word g
30486 void FFScript::getComboData_create_enemy_when(){ GET_COMBODATA_TYPE_INT(create_enemy_when); } //byte h
30487 void FFScript::getComboData_create_enemy_change(){ GET_COMBODATA_TYPE_INT(create_enemy_change); } //int32_t i
30488 void FFScript::getComboData_directional_change_type(){ GET_COMBODATA_TYPE_INT(directional_change_type); } //byte j
30489 void FFScript::getComboData_distance_change_tiles(){ GET_COMBODATA_TYPE_INT(distance_change_tiles); } //int32_t k
30490 void FFScript::getComboData_dive_item(){ GET_COMBODATA_TYPE_INT(dive_item); } //int16_t l
30491 void FFScript::getComboData_dock(){ GET_COMBODATA_TYPE_INT(dock); } //byte m
30492 void FFScript::getComboData_fairy(){ GET_COMBODATA_TYPE_INT(fairy); } //byte n
30493 void FFScript::getComboData_ff_combo_attr_change(){ GET_COMBODATA_TYPE_INT(ff_combo_attr_change); } //byte o
30494 void FFScript::getComboData_foot_decorations_tile(){ GET_COMBODATA_TYPE_INT(foot_decorations_tile); } //int32_t p
30495 void FFScript::getComboData_foot_decorations_type(){ GET_COMBODATA_TYPE_INT(foot_decorations_type); } //byte q
30496 void FFScript::getComboData_hookshot_grab_point(){ GET_COMBODATA_TYPE_INT(hookshot_grab_point); } //byte r
30497 void FFScript::getComboData_ladder_pass(){ GET_COMBODATA_TYPE_INT(ladder_pass); } //byte s
30498 void FFScript::getComboData_lock_block_type(){ GET_COMBODATA_TYPE_INT(lock_block_type); } //byte t
30499 void FFScript::getComboData_lock_block_change(){ GET_COMBODATA_TYPE_INT(lock_block_change); } //int32_t u
30500 void FFScript::getComboData_magic_mirror_type(){ GET_COMBODATA_TYPE_INT(magic_mirror_type); } //byte v
30501 void FFScript::getComboData_modify_hp_amount(){ GET_COMBODATA_TYPE_INT(modify_hp_amount); } //int16_t w
30502 void FFScript::getComboData_modify_hp_delay(){ GET_COMBODATA_TYPE_INT(modify_hp_delay); } //byte x
30503 void FFScript::getComboData_modify_hp_type(){ GET_COMBODATA_TYPE_INT(modify_hp_type); } //byte y
30504 void FFScript::getComboData_modify_mp_amount(){ GET_COMBODATA_TYPE_INT(modify_mp_amount); } //int16_t z
30505 void FFScript::getComboData_modify_mp_delay(){ GET_COMBODATA_TYPE_INT(modify_mp_delay); } //byte aa
30506 void FFScript::getComboData_modify_mp_type(){ GET_COMBODATA_TYPE_INT(modify_mp_type); } //byte ab
30507 void FFScript::getComboData_no_push_blocks(){ GET_COMBODATA_TYPE_INT(no_push_blocks); } //byte ac
30508 void FFScript::getComboData_overhead(){ GET_COMBODATA_TYPE_INT(overhead); } //byte ad
30509 void FFScript::getComboData_place_enemy(){ GET_COMBODATA_TYPE_INT(place_enemy); } //byte ae
30510 void FFScript::getComboData_push_direction(){ GET_COMBODATA_TYPE_INT(push_direction); } //byte af
30511 void FFScript::getComboData_push_weight(){ GET_COMBODATA_TYPE_INT(push_weight); } //byte ag heavy or not
30512 void FFScript::getComboData_push_wait(){ GET_COMBODATA_TYPE_INT(push_wait); } //byte ah
30513 void FFScript::getComboData_pushed(){ GET_COMBODATA_TYPE_INT(pushed); } //byte ai
30514 void FFScript::getComboData_raft(){ GET_COMBODATA_TYPE_INT(raft); } //byte aj
30515 void FFScript::getComboData_reset_room(){ GET_COMBODATA_TYPE_INT(reset_room); } //byte ak
30516 void FFScript::getComboData_save_point_type(){ GET_COMBODATA_TYPE_INT(save_point_type); } //byte al
30517 void FFScript::getComboData_screen_freeze_type(){ GET_COMBODATA_TYPE_INT(screen_freeze_type); } //byte am
30518
30519 void FFScript::getComboData_secret_combo(){ GET_COMBODATA_TYPE_INT(secret_combo); } //byte an
30520 void FFScript::getComboData_singular(){ GET_COMBODATA_TYPE_INT(singular); } //byte ao
30521 void FFScript::getComboData_slow_movement(){ GET_COMBODATA_TYPE_INT(slow_movement); } //byte ap
30522 void FFScript::getComboData_statue_type(){ GET_COMBODATA_TYPE_INT(statue_type); } //byte aq
30523 void FFScript::getComboData_step_type(){ GET_COMBODATA_TYPE_INT(step_type); } //byte ar
30524 void FFScript::getComboData_step_change_to(){ GET_COMBODATA_TYPE_INT(step_change_to); } //int32_t as
30525 void FFScript::getComboData_strike_remnants(){ GET_COMBODATA_TYPE_INT(strike_remnants); } //int32_t au
30526 void FFScript::getComboData_strike_remnants_type(){ GET_COMBODATA_TYPE_INT(strike_remnants_type); } //byte av
30527 void FFScript::getComboData_strike_change(){ GET_COMBODATA_TYPE_INT(strike_change); } //int32_t aw
30528 void FFScript::getComboData_strike_item(){ GET_COMBODATA_TYPE_INT(strike_item); } //int16_t ax
30529 void FFScript::getComboData_touch_item(){ GET_COMBODATA_TYPE_INT(touch_item); } //int16_t ay
30530 void FFScript::getComboData_touch_stairs(){ GET_COMBODATA_TYPE_INT(touch_stairs); } //byte az
30531 void FFScript::getComboData_trigger_type(){ GET_COMBODATA_TYPE_INT(trigger_type); } //byte ba
30532 void FFScript::getComboData_trigger_sensitive(){ GET_COMBODATA_TYPE_INT(trigger_sensitive); } //byte bb
30533 void FFScript::getComboData_warp_type(){ GET_COMBODATA_TYPE_INT(warp_type); } //byte bc
30534 void FFScript::getComboData_warp_sensitive(){ GET_COMBODATA_TYPE_INT(warp_sensitive); } //byte bd
30535 void FFScript::getComboData_warp_direct(){ GET_COMBODATA_TYPE_INT(warp_direct); } //byte be
30536 void FFScript::getComboData_warp_location(){ GET_COMBODATA_TYPE_INT(warp_location); } //byte bf
30537 void FFScript::getComboData_water(){ GET_COMBODATA_TYPE_INT(water); } //byte bg
30538 void FFScript::getComboData_whistle(){ GET_COMBODATA_TYPE_INT(whistle); } //byte bh
30539 void FFScript::getComboData_win_game(){ GET_COMBODATA_TYPE_INT(win_game); } //byte bi
30540 void FFScript::getComboData_block_weapon_lvl(){ GET_COMBODATA_TYPE_INT(block_weapon_lvl); } //byte bj - max level of weapon to block
30541
30542 void FFScript::getComboData_tile(){ GET_COMBODATA_VAR_INT(tile); } //newcombo, word
30543 void FFScript::getComboData_flip(){ GET_COMBODATA_VAR_INT(flip); } //newcombo byte
30544
30545 void FFScript::getComboData_walk(){ GET_COMBODATA_VAR_INT(walk); } //newcombo byte
30546 void FFScript::getComboData_type(){ GET_COMBODATA_VAR_INT(type); } //newcombo byte
30547 void FFScript::getComboData_csets(){ GET_COMBODATA_VAR_INT(csets); } //newcombo byte
30548 void FFScript::getComboData_frames(){ GET_COMBODATA_VAR_INT(frames); } //newcombo byte
30549 void FFScript::getComboData_speed(){ GET_COMBODATA_VAR_INT(speed); } //newcombo byte
30550 void FFScript::getComboData_nextcombo(){ GET_COMBODATA_VAR_INT(nextcombo); } //newcombo word
30551 void FFScript::getComboData_nextcset(){ GET_COMBODATA_VAR_INT(nextcset); } //newcombo byte
30552 void FFScript::getComboData_flag(){ GET_COMBODATA_VAR_INT(flag); } //newcombo byte
30553 void FFScript::getComboData_skipanim(){ GET_COMBODATA_VAR_INT(skipanim); } //newcombo byte
30554 void FFScript::getComboData_nexttimer(){ GET_COMBODATA_VAR_INT(nexttimer); } //newcombo word
30555 void FFScript::getComboData_skipanimy(){ GET_COMBODATA_VAR_INT(skipanimy); } //newcombo byte
30556 void FFScript::getComboData_animflags(){ GET_COMBODATA_VAR_INT(animflags); } //newcombo byte
30557
30558
30559 //two inputs, one return
30560 void FFScript::getComboData_block_weapon(){ GET_COMBODATA_TYPE_INDEX(block_weapon,32); } //byte array[32] d (ID of LWeapon)
30561 void FFScript::getComboData_strike_weapons(){ GET_COMBODATA_TYPE_INDEX(strike_weapons,32); } //byte at, arr[32]
30562
30563 //Setters, two inputs no returns
30564
30565 void FFScript::setComboData_block_enemies(){ SET_COMBODATA_TYPE_INT(block_enemies,ZS_BYTE); } //byte a
30566 void FFScript::setComboData_block_hole(){ SET_COMBODATA_TYPE_INT(block_hole,ZS_BYTE); } //byte b
30567 void FFScript::setComboData_block_trigger(){ SET_COMBODATA_TYPE_INT(block_trigger,ZS_BYTE); } //byte c
30568 void FFScript::setComboData_conveyor_x_speed(){ SET_COMBODATA_TYPE_INT(conveyor_x_speed,ZS_SHORT); } //int16_t e
30569 void FFScript::setComboData_conveyor_y_speed(){ SET_COMBODATA_TYPE_INT(conveyor_y_speed,ZS_SHORT); } //int16_t f
30570 void FFScript::setComboData_create_enemy(){ SET_COMBODATA_TYPE_INT(create_enemy,ZS_WORD); } //word g
30571 void FFScript::setComboData_create_enemy_when(){ SET_COMBODATA_TYPE_INT(create_enemy_when,ZS_BYTE); } //byte h
30572 void FFScript::setComboData_create_enemy_change(){ SET_COMBODATA_TYPE_INT(create_enemy_change,ZS_LONG); } //int32_t i
30573 void FFScript::setComboData_directional_change_type(){ SET_COMBODATA_TYPE_INT(directional_change_type,ZS_BYTE); } //byte j
30574 void FFScript::setComboData_distance_change_tiles(){ SET_COMBODATA_TYPE_INT(distance_change_tiles,ZS_LONG); } //int32_t k
30575 void FFScript::setComboData_dive_item(){ SET_COMBODATA_TYPE_INT(dive_item,ZS_SHORT); } //int16_t l
30576 void FFScript::setComboData_dock(){ SET_COMBODATA_TYPE_INT(dock,ZS_BYTE); } //byte m
30577 void FFScript::setComboData_fairy(){ SET_COMBODATA_TYPE_INT(fairy,ZS_BYTE); } //byte n
30578 void FFScript::setComboData_ff_combo_attr_change(){ SET_COMBODATA_TYPE_INT(ff_combo_attr_change,ZS_BYTE); } //byte o
30579 void FFScript::setComboData_foot_decorations_tile(){ SET_COMBODATA_TYPE_INT(foot_decorations_tile,ZS_LONG); } //int32_t p
30580 void FFScript::setComboData_foot_decorations_type(){ SET_COMBODATA_TYPE_INT(foot_decorations_type,ZS_BYTE); } //byte q
30581 void FFScript::setComboData_hookshot_grab_point(){ SET_COMBODATA_TYPE_INT(hookshot_grab_point,ZS_BYTE); } //byte r
30582 void FFScript::setComboData_ladder_pass(){ SET_COMBODATA_TYPE_INT(ladder_pass,ZS_BYTE); } //byte s
30583 void FFScript::setComboData_lock_block_type(){ SET_COMBODATA_TYPE_INT(lock_block_type,ZS_BYTE); } //byte t
30584 void FFScript::setComboData_lock_block_change(){ SET_COMBODATA_TYPE_INT(lock_block_change,ZS_LONG); } //int32_t u
30585 void FFScript::setComboData_magic_mirror_type(){ SET_COMBODATA_TYPE_INT(magic_mirror_type,ZS_BYTE); } //byte v
30586 void FFScript::setComboData_modify_hp_amount(){ SET_COMBODATA_TYPE_INT(modify_hp_amount,ZS_SHORT); } //int16_t w
30587 void FFScript::setComboData_modify_hp_delay(){ SET_COMBODATA_TYPE_INT(modify_hp_delay,ZS_BYTE); } //byte x
30588 void FFScript::setComboData_modify_hp_type(){ SET_COMBODATA_TYPE_INT(modify_hp_type,ZS_BYTE); } //byte y
30589 void FFScript::setComboData_modify_mp_amount(){ SET_COMBODATA_TYPE_INT(modify_mp_amount,ZS_SHORT); } //int16_t z
30590 void FFScript::setComboData_modify_mp_delay(){ SET_COMBODATA_TYPE_INT(modify_mp_delay,ZS_BYTE); } //byte aa
30591 void FFScript::setComboData_modify_mp_type(){ SET_COMBODATA_TYPE_INT(modify_mp_type,ZS_BYTE); } //byte ab
30592 void FFScript::setComboData_no_push_blocks(){ SET_COMBODATA_TYPE_INT(no_push_blocks,ZS_BYTE); } //byte ac
30593 void FFScript::setComboData_overhead(){ SET_COMBODATA_TYPE_INT(overhead,ZS_BYTE); } //byte ad
30594 void FFScript::setComboData_place_enemy(){ SET_COMBODATA_TYPE_INT(place_enemy,ZS_BYTE); } //byte ae
30595 void FFScript::setComboData_push_direction(){ SET_COMBODATA_TYPE_INT(push_direction,ZS_BYTE); } //byte af
30596 void FFScript::setComboData_push_weight(){ SET_COMBODATA_TYPE_INT(push_weight,ZS_BYTE); } //byte ag heavy or not
30597 void FFScript::setComboData_push_wait(){ SET_COMBODATA_TYPE_INT(push_wait,ZS_BYTE); } //byte ah
30598 void FFScript::setComboData_pushed(){ SET_COMBODATA_TYPE_INT(pushed,ZS_BYTE); } //byte ai
30599 void FFScript::setComboData_raft(){ SET_COMBODATA_TYPE_INT(raft,ZS_BYTE); } //byte aj
30600 void FFScript::setComboData_reset_room(){ SET_COMBODATA_TYPE_INT(reset_room,ZS_BYTE); } //byte ak
30601 void FFScript::setComboData_save_point_type(){ SET_COMBODATA_TYPE_INT(save_point_type,ZS_BYTE); } //byte al
30602 void FFScript::setComboData_screen_freeze_type(){ SET_COMBODATA_TYPE_INT(screen_freeze_type,ZS_BYTE); } //byte am
30603
30604 void FFScript::setComboData_secret_combo(){ SET_COMBODATA_TYPE_INT(secret_combo,ZS_BYTE); } //byte an
30605 void FFScript::setComboData_singular(){ SET_COMBODATA_TYPE_INT(singular,ZS_BYTE); } //byte ao
30606 void FFScript::setComboData_slow_movement(){ SET_COMBODATA_TYPE_INT(slow_movement,ZS_BYTE); } //byte ap
30607 void FFScript::setComboData_statue_type(){ SET_COMBODATA_TYPE_INT(statue_type,ZS_BYTE); } //byte aq
30608 void FFScript::setComboData_step_type(){ SET_COMBODATA_TYPE_INT(step_type,ZS_BYTE); } //byte ar
30609 void FFScript::setComboData_step_change_to(){ SET_COMBODATA_TYPE_INT(step_change_to,ZS_LONG); } //int32_t as
30610
30611 void FFScript::setComboData_strike_remnants(){ SET_COMBODATA_TYPE_INT(strike_remnants,ZS_LONG); } //int32_t au
30612 void FFScript::setComboData_strike_remnants_type(){ SET_COMBODATA_TYPE_INT(strike_remnants_type,ZS_BYTE); } //byte av
30613 void FFScript::setComboData_strike_change(){ SET_COMBODATA_TYPE_INT(strike_change,ZS_LONG); } //int32_t aw
30614 void FFScript::setComboData_strike_item(){ SET_COMBODATA_TYPE_INT(strike_item,ZS_SHORT); } //int16_t ax
30615 void FFScript::setComboData_touch_item(){ SET_COMBODATA_TYPE_INT(touch_item,ZS_SHORT); } //int16_t ay
30616 void FFScript::setComboData_touch_stairs(){ SET_COMBODATA_TYPE_INT(touch_stairs,ZS_BYTE); } //byte az
30617 void FFScript::setComboData_trigger_type(){ SET_COMBODATA_TYPE_INT(trigger_type,ZS_BYTE); } //byte ba
30618 void FFScript::setComboData_trigger_sensitive(){ SET_COMBODATA_TYPE_INT(trigger_sensitive,ZS_BYTE); } //byte bb
30619 void FFScript::setComboData_warp_type(){ SET_COMBODATA_TYPE_INT(warp_type,ZS_BYTE); } //byte bc
30620 void FFScript::setComboData_warp_sensitive(){ SET_COMBODATA_TYPE_INT(warp_sensitive,ZS_BYTE); } //byte bd
30621 void FFScript::setComboData_warp_direct(){ SET_COMBODATA_TYPE_INT(warp_direct,ZS_BYTE); } //byte be
30622 void FFScript::setComboData_warp_location(){ SET_COMBODATA_TYPE_INT(warp_location,ZS_BYTE); } //byte bf
30623 void FFScript::setComboData_water(){ SET_COMBODATA_TYPE_INT(water,ZS_BYTE); } //byte bg
30624 void FFScript::setComboData_whistle(){ SET_COMBODATA_TYPE_INT(whistle,ZS_BYTE); } //byte bh
30625 void FFScript::setComboData_win_game(){ SET_COMBODATA_TYPE_INT(win_game,ZS_BYTE); } //byte bi
30626 void FFScript::setComboData_block_weapon_lvl(){ SET_COMBODATA_TYPE_INT(block_weapon_lvl,ZS_BYTE); } //byte bj - max level of weapon to block
30627
30628 //combobuf
30629 void FFScript::setComboData_tile(){ SET_COMBODATA_VAR_INT(tile,ZS_WORD); } //newcombo, word
30630 void FFScript::setComboData_flip(){ SET_COMBODATA_VAR_INT(flip,ZS_BYTE); } //newcombo byte
30631
30632 void FFScript::setComboData_walk(){ SET_COMBODATA_VAR_INT(walk,ZS_BYTE); } //newcombo byte
30633 void FFScript::setComboData_type(){ SET_COMBODATA_VAR_INT(type,ZS_BYTE); } //newcombo byte
30634 void FFScript::setComboData_csets(){ SET_COMBODATA_VAR_INT(csets,ZS_BYTE); } //newcombo byte
30635 void FFScript::setComboData_frames(){ SET_COMBODATA_VAR_INT(frames,ZS_BYTE); } //newcombo byte
30636 void FFScript::setComboData_speed(){ SET_COMBODATA_VAR_INT(speed,ZS_BYTE); } //newcombo byte
30637 void FFScript::setComboData_nextcombo(){ SET_COMBODATA_VAR_INT(nextcombo,ZS_WORD); } //newcombo word
30638 void FFScript::setComboData_nextcset(){ SET_COMBODATA_VAR_INT(nextcset,ZS_BYTE); } //newcombo byte
30639 void FFScript::setComboData_flag(){ SET_COMBODATA_VAR_INT(flag,ZS_BYTE); } //newcombo byte
30640 void FFScript::setComboData_skipanim(){ SET_COMBODATA_VAR_INT(skipanim,ZS_BYTE); } //newcombo byte
30641 void FFScript::setComboData_nexttimer(){ SET_COMBODATA_VAR_INT(nexttimer,ZS_WORD); } //newcombo word
30642 void FFScript::setComboData_skipanimy(){ SET_COMBODATA_VAR_INT(skipanimy,ZS_BYTE); } //newcombo byte
30643 void FFScript::setComboData_animflags(){ SET_COMBODATA_VAR_INT(animflags,ZS_BYTE); } //newcombo byte
30644
30645 //three inputs, no returns
30646 void FFScript::setComboData_block_weapon(int32_t v){ SET_COMBODATA_TYPE_INDEX(block_weapon,v,ZS_BYTE,32); } //byte array[32] d (ID of LWeapon)
30647 void FFScript::setComboData_strike_weapons(int32_t v){ SET_COMBODATA_TYPE_INDEX(strike_weapons,v,ZS_BYTE,32); } //byte at, arr[32]
30648
30649 //SpriteData Macros
30650 #define GET_SPRITEDATA_TYPE_INT(member) \
30651 { \
30652 int32_t ID = vbound((get_register(sarg2) / 10000),0,255);\
30653 set_register(sarg1, wpnsbuf[ID].member * 10000); \
30654 }
30655
30656 #define SET_SPRITEDATA_TYPE_INT(member, bound) \
30657 { \
30658 int32_t ID = get_register(sarg1) / 10000; \
30659 int32_t val = vbound( (get_register(sarg2) / 10000), 0, bound); \
30660 if(ID < 1 || ID > 255) \
30661 set_register(sarg1, -10000); \
30662 else \
30663 wpnsbuf[ID].member = val; \
30664 }
30665
30666 #define SET_SPRITEDATA_TYPE_INT_NOBOUND(member) \
30667 { \
30668 int32_t ID = get_register(sarg1) / 10000; \
30669 int32_t val = get_register(sarg2) / 10000; \
30670 if(ID < 1 || ID > 255) \
30671 set_register(sarg1, -10000); \
30672 else \
30673 wpnsbuf[ID].member = val; \
30674 }
30675
30676
30677 void FFScript::getSpriteDataTile(){GET_SPRITEDATA_TYPE_INT(tile);}
30678 void FFScript::getSpriteDataMisc(){GET_SPRITEDATA_TYPE_INT(misc);}
30679 void FFScript::getSpriteDataCSets(){GET_SPRITEDATA_TYPE_INT(csets);}
30680 void FFScript::getSpriteDataFrames(){GET_SPRITEDATA_TYPE_INT(frames);}
30681 void FFScript::getSpriteDataSpeed(){GET_SPRITEDATA_TYPE_INT(speed);}
30682 void FFScript::getSpriteDataType(){GET_SPRITEDATA_TYPE_INT(type);}
30683
30684
30685
30686 void FFScript::setSpriteDataTile(){SET_SPRITEDATA_TYPE_INT(tile,ZS_WORD);}
30687 void FFScript::setSpriteDataMisc(){SET_SPRITEDATA_TYPE_INT(misc,ZS_CHAR);}
30688 void FFScript::setSpriteDataCSets(){SET_SPRITEDATA_TYPE_INT(csets,ZS_CHAR);}
30689 void FFScript::setSpriteDataFrames(){SET_SPRITEDATA_TYPE_INT(frames,ZS_CHAR);}
30690 void FFScript::setSpriteDataSpeed(){SET_SPRITEDATA_TYPE_INT(speed,ZS_CHAR);}
30691 void FFScript::setSpriteDataType(){SET_SPRITEDATA_TYPE_INT(type,ZS_CHAR);}
30692
30693
30694 2004 void FFScript::do_setMIDI_volume(int32_t m)
30695 {
30696 2004 master_volume(-1,(vbound(m,0,255)));
30697 2004 }
30698 2004 void FFScript::do_setMusic_volume(int32_t m)
30699 {
30700 2004 emusic_volume = vbound(m,0,255);
30701 2004 }
30702 2004 void FFScript::do_setDIGI_volume(int32_t m)
30703 {
30704 2004 master_volume((vbound(m,0,255)),-1);
30705 2004 }
30706 void FFScript::do_setSFX_volume(int32_t m)
30707 {
30708 sfx_volume = m;
30709 }
30710 void FFScript::do_setSFX_pan(int32_t m)
30711 {
30712 pan_style = vbound(m,0,3);
30713 }
30714 8 int32_t FFScript::do_getMIDI_volume()
30715 {
30716 8 return ((int32_t)midi_volume);
30717 }
30718 8 int32_t FFScript::do_getMusic_volume()
30719 {
30720 8 return ((int32_t)emusic_volume);
30721 }
30722 8 int32_t FFScript::do_getDIGI_volume()
30723 {
30724 8 return ((int32_t)digi_volume);
30725 }
30726 int32_t FFScript::do_getSFX_volume()
30727 {
30728 return ((int32_t)sfx_volume);
30729 }
30730 int32_t FFScript::do_getSFX_pan()
30731 {
30732 return ((int32_t)pan_style);
30733 }
30734
30735
30736 //Change Game Over Screen Values
30737 void FFScript::FFSetSaveScreenSetting()
30738 {
30739
30740 int32_t indx = get_register(sarg1) / 10000;
30741 int32_t value = get_register(sarg2) / 10000; //bounded in zelda.cpp
30742 if(indx < 0 || indx > 11)
30743 set_register(sarg1, -10000);
30744 else
30745 SetSaveScreenSetting(indx, value);
30746 }
30747
30748
30749
30750 void FFScript::FFChangeSubscreenText()
30751 {
30752
30753 int32_t index = get_register(sarg1) / 10000;
30754 int32_t arrayptr = get_register(sarg2);
30755
30756 if ( index < 0 || index > 3 )
30757 {
30758 al_trace("The index supplied to Game->SetSubscreenText() is invalid. The index specified was: %d /n", index);
30759 return;
30760 }
30761
30762 string filename_str;
30763 ArrayH::getString(arrayptr, filename_str, 73);
30764 ChangeSubscreenText(index,filename_str.c_str());
30765 }
30766
30767 20 void FFScript::SetItemMessagePlayed(int32_t itm)
30768 {
30769 20 game->item_messages_played[itm] = 1;
30770 20 }
30771 15 bool FFScript::GetItemMessagePlayed(int32_t itm)
30772 {
30773 15 return ((game->item_messages_played[itm] ) ? true : false);
30774 }
30775
30776 int32_t FFScript::getQRBit(int32_t rule)
30777 {
30778 return ( get_qr(rule) ? 1 : 0 );
30779 }
30780
30781 25464276 void FFScript::setHeroAction(int32_t a)
30782 {
30783 25464276 FF_hero_action = vbound(a, 0, 255);
30784 25464276 }
30785
30786 92396325 int32_t FFScript::getHeroAction()
30787 {
30788 92396325 int32_t special_action = Hero.getAction2();
30789
2/2
✓ Branch 0 taken 557092 times.
✓ Branch 1 taken 91839233 times.
92396325 if ( special_action != -1 ) return special_action; //spin, dive, charge
30790 91839233 else return FF_hero_action; //everything else
30791 92396325 }
30792
30793 1077 void FFScript::init()
30794 {
30795 1077 apply_qr_rules();
30796 1077 eventData.clear();
30797 1077 countGenScripts();
30798 // Some scripts can run even before ~Init (but only if qr_OLD_INIT_SCRIPT_TIMING is on), so figure out
30799 // the global register types ahead of time.
30800 1077 markGlobalRegisters();
30801
2/2
✓ Branch 0 taken 10770 times.
✓ Branch 1 taken 1077 times.
11847 for ( int32_t q = 0; q < wexLast; q++ ) warpex[q] = 0;
30802 1077 temp_no_stepforward = 0;
30803 1077 nostepforward = 0;
30804 1077 numscriptdraws = 0;
30805 1077 skipscriptdraws = false;
30806 1077 max_ff_rules = qr_MAX;
30807 1077 coreflags = 0;
30808 1077 skip_ending_credits = 0;
30809 1077 music_update_cond = 0;
30810 1077 music_update_flags = 0;
30811 //quest_format : is this properly initialised?
30812
2/2
✓ Branch 0 taken 73236 times.
✓ Branch 1 taken 1077 times.
74313 for ( int32_t q = 0; q < susptLAST; q++ ) { system_suspend[q] = 0; }
30813
30814 1077 usr_midi_volume = midi_volume;
30815 1077 usr_digi_volume = digi_volume;
30816 1077 usr_sfx_volume = sfx_volume;
30817 1077 usr_music_volume = emusic_volume;
30818
30819 1077 usr_panstyle = pan_style;
30820 1077 FF_hero_action = 0;
30821 1077 enemy_removal_point[spriteremovalY1] = -32767;
30822 1077 enemy_removal_point[spriteremovalY2] = 32767;
30823 1077 enemy_removal_point[spriteremovalX1] = -32767;
30824 1077 enemy_removal_point[spriteremovalX2] = 32767;
30825 1077 enemy_removal_point[spriteremovalZ1] = -32767;
30826 1077 enemy_removal_point[spriteremovalZ2] = 32767;
30827
30828
2/2
✓ Branch 0 taken 4308 times.
✓ Branch 1 taken 1077 times.
5385 for ( int32_t q = 0; q < 4; q++ )
30829 {
30830 4308 FF_screenbounds[q] = 0;
30831 4308 FF_screen_dimensions[q] = 0;
30832 4308 FF_subscreen_dimensions[q] = 0;
30833 4308 FF_eweapon_removal_bounds[q] = 0;
30834 4308 FF_lweapon_removal_bounds[q] = 0;
30835 4308 }
30836
2/2
✓ Branch 0 taken 10770 times.
✓ Branch 1 taken 1077 times.
11847 for ( int32_t q = 0; q < FFSCRIPTCLASS_CLOCKS; q++ )
30837 {
30838 10770 FF_clocks[q] = 0;
30839 10770 }
30840
2/2
✓ Branch 0 taken 21540 times.
✓ Branch 1 taken 1077 times.
22617 for ( int32_t q = 0; q < SCRIPT_DRAWING_RULES; q++ )
30841 {
30842 21540 ScriptDrawingRules[q] = 0;
30843 21540 }
30844
2/2
✓ Branch 0 taken 6462 times.
✓ Branch 1 taken 1077 times.
7539 for ( int32_t q = 0; q < NUM_USER_MIDI_OVERRIDES; q++ )
30845 {
30846 6462 FF_UserMidis[q] = 0;
30847 6462 }
30848 1077 subscreen_scroll_speed = 0; //make a define for a default and read quest override! -Z
30849 1077 kb_typing_mode = false;
30850 1077 initIncludePaths();
30851 //clearRunningItemScripts();
30852 1077 ScrollingScreensAll.clear();
30853 1077 memset(ScrollingData, 0, sizeof(int32_t) * SZ_SCROLLDATA);
30854 1077 ScrollingData[SCROLLDATA_DIR] = -1;
30855 1077 user_rng_init();
30856 1077 clear_script_engine_data();
30857
2/2
✓ Branch 0 taken 72625 times.
✓ Branch 1 taken 1077 times.
73702 for (auto &it : jitted_scripts)
30858 {
30859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72625 times.
72625 if (it.second) jit_delete_script_handle(it.second);
30860 }
30861 1077 jitted_scripts.clear();
30862 1077 script_debug_handles.clear();
30863 1077 runtime_script_debug_handle = nullptr;
30864 1077 }
30865
30866 310 void FFScript::shutdown()
30867 {
30868
2/2
✓ Branch 0 taken 6808 times.
✓ Branch 1 taken 310 times.
7118 for (auto &it : jitted_scripts)
30869 {
30870
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6805 times.
6808 if (it.second) jit_delete_script_handle(it.second);
30871 }
30872 310 jitted_scripts.clear();
30873 310 objectRAM.clear();
30874 310 script_objects.clear();
30875 310 }
30876
30877
30878 12 void FFScript::SetFFEngineFlag(int32_t flag, bool state)
30879 {
30880
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if ( state ) { coreflags |= flag; }
30881 else coreflags &= ~flag;
30882 12 }
30883
30884 void FFScript::setSubscreenScrollSpeed(byte n)
30885 {
30886 subscreen_scroll_speed = n;
30887 }
30888
30889 int32_t FFScript::getSubscreenScrollSpeed()
30890 {
30891 return (int32_t)subscreen_scroll_speed;
30892 }
30893
30894 void FFScript::do_greyscale(const bool v)
30895 {
30896 // This has been removed.
30897 }
30898
30899 void FFScript::do_monochromatic(const bool v)
30900 {
30901 // This has been removed.
30902 }
30903
30904 10680 static int convert_6bit_to_8bit_color_shift_arg(int v)
30905 {
30906 10680 int va = abs(v);
30907
2/2
✓ Branch 0 taken 10677 times.
✓ Branch 1 taken 3 times.
10680 if (va < 64)
30908 10677 return _rgb_scale_6[va] * sign(v);
30909
30910 3 int vdiv = va / 63;
30911 3 int vmod = va % 63;
30912 3 return (vdiv * 255 + _rgb_scale_6[vmod]) * sign(v);
30913 10680 }
30914
30915 void FFScript::gfxmonohue()
30916 {
30917 int32_t r = SH::read_stack(ri->sp + 3) / 10000;
30918 int32_t g = SH::read_stack(ri->sp + 2) / 10000;
30919 int32_t b = SH::read_stack(ri->sp + 1) / 10000;
30920 if (!scripting_use_8bit_colors)
30921 {
30922 r = convert_6bit_to_8bit_color_shift_arg(r);
30923 g = convert_6bit_to_8bit_color_shift_arg(g);
30924 b = convert_6bit_to_8bit_color_shift_arg(b);
30925 }
30926 bool m = (SH::read_stack(ri->sp + 0) / 10000);
30927 doGFXMonohue(r,g,b,m);
30928 }
30929
30930 66 void FFScript::clearTint()
30931 {
30932 66 doClearTint();
30933 66 }
30934
30935 3560 void FFScript::Tint()
30936 {
30937 3560 int32_t r = SH::read_stack(ri->sp + 2) / 10000;
30938 3560 int32_t g = SH::read_stack(ri->sp + 1) / 10000;
30939 3560 int32_t b = SH::read_stack(ri->sp + 0) / 10000;
30940
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3560 times.
3560 if (!scripting_use_8bit_colors)
30941 {
30942 3560 r = convert_6bit_to_8bit_color_shift_arg(r);
30943 3560 g = convert_6bit_to_8bit_color_shift_arg(g);
30944 3560 b = convert_6bit_to_8bit_color_shift_arg(b);
30945 3560 }
30946 3560 doTint(r,g,b);
30947 3560 }
30948
30949 void FFScript::do_fx_zap(const bool v)
30950 {
30951 int32_t out = SH::get_arg(sarg1, v);
30952
30953 if ( out ) { FFScript::do_zapout(); }
30954 else FFScript::do_zapin();
30955 }
30956
30957 void FFScript::do_fx_wavy(const bool v)
30958 {
30959 int32_t out = SH::get_arg(sarg1, v);
30960
30961 if ( out ) { FFScript::do_wavyout(); }
30962 else FFScript::do_wavyin();
30963 }
30964
30965 499086527 int32_t FFScript::getQuestHeaderInfo(int32_t type)
30966 {
30967 499086527 return quest_format[type];
30968 }
30969
30970 string get_filestr(const bool relative, bool is_file) //Used for 'FileSystem' functions.
30971 {
30972 int32_t strptr = get_register(sarg1);
30973 string user_path;
30974 ArrayH::getString(strptr, user_path, 512);
30975
30976 if (!relative)
30977 {
30978 user_path = user_path.substr(user_path.find_first_not_of('/'),string::npos); //Kill leading '/'
30979 size_t last = user_path.find_last_not_of('/');
30980 if(last!=string::npos)++last;
30981 user_path = user_path.substr(0,last); //Kill trailing '/'
30982 return user_path;
30983 }
30984
30985 if (auto r = parse_user_path(user_path, is_file); !r)
30986 {
30987 scripting_log_error_with_context("Error: {}", r.error());
30988 return "";
30989 } else return r.value();
30990 }
30991
30992 void FFScript::do_checkdir(const bool is_dir)
30993 {
30994 string resolved_path = get_filestr(get_qr(qr_BITMAP_AND_FILESYSTEM_PATHS_ALWAYS_RELATIVE), false);
30995 set_register(sarg1, !resolved_path.empty() && checkPath(resolved_path.c_str(), is_dir) ? 10000 : 0);
30996 }
30997
30998 void FFScript::do_fs_remove()
30999 {
31000 string resolved_path = get_filestr(true, true);
31001 set_register(sarg1, !resolved_path.empty() && remove(resolved_path.c_str()) ? 0 : 10000);
31002 }
31003
31004 100 void FFScript::Play_Level_Music()
31005 {
31006 100 int32_t m = hero_scr->screen_midi;
31007
31008
1/6
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
100 switch(m)
31009 {
31010 case -2:
31011 music_stop();
31012 break;
31013
31014 case -1:
31015 100 play_DmapMusic();
31016 100 break;
31017
31018 case 1:
31019 jukebox(ZC_MIDI_OVERWORLD);
31020 break;
31021
31022 case 2:
31023 jukebox(ZC_MIDI_DUNGEON);
31024 break;
31025
31026 case 3:
31027 jukebox(ZC_MIDI_LEVEL9);
31028 break;
31029
31030 default:
31031 if(m>=4 && m<4+MAXCUSTOMMIDIS)
31032 jukebox(m+MIDIOFFSET_MAPSCR);
31033 else
31034 music_stop();
31035 }
31036 100 }
31037
31038 92 void FFScript::do_warp_ex(bool v)
31039 {
31040 92 int32_t zscript_array_ptr = SH::get_arg(sarg1, v);
31041 92 ArrayManager am(zscript_array_ptr);
31042
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if(am.invalid()) return;
31043 92 int32_t zscript_array_size = am.size();
31044
1/2
✓ Branch 0 taken 92 times.
✗ Branch 1 not taken.
92 switch(zscript_array_size)
31045 {
31046 case 8: // {int32_t type, int32_t dmap, int32_t screen, int32_t x, int32_t y, int32_t effect, int32_t sound, int32_t flags}
31047 case 9: // {int32_t type, int32_t dmap, int32_t screen, int32_t x, int32_t y, int32_t effect, int32_t sound, int32_t flags, int32_t dir}
31048 {
31049 92 int32_t tmpwarp[9]={0};
31050
2/2
✓ Branch 0 taken 736 times.
✓ Branch 1 taken 92 times.
828 for ( int32_t q = 0; q < 8; q++ )
31051 {
31052 736 tmpwarp[q] = (am.get(q)/10000);
31053 736 }
31054
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 66 times.
92 tmpwarp[wexDir] = zscript_array_size < 9 ? -1 : (am.get(8)/10000);\
31055
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if ( ((unsigned)tmpwarp[1]) >= MAXDMAPS )
31056 {
31057 Z_scripterrlog("Invalid DMap ID (%d) passed to WarpEx(). Aborting.\n", tmpwarp[1]);
31058 return;
31059 }
31060
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if ( ((unsigned)tmpwarp[2]) >= MAPSCRS )
31061 {
31062 Z_scripterrlog("Invalid Screen Index (%d) passed to WarpEx(). Aborting.\n", tmpwarp[2]);
31063 return;
31064 }
31065 //Extra sanity guard.
31066
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if ( map_screen_index(DMaps[tmpwarp[1]].map, tmpwarp[2] + DMaps[tmpwarp[1]].xoff) >= (int32_t)TheMaps.size() )
31067 {
31068 Z_scripterrlog("Invalid destination passed to WarpEx(). Aborting.\n");
31069 return;
31070 }
31071
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92 times.
92 if(get_qr(qr_OLD_BROKEN_WARPEX_MUSIC))
31072 {
31073
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 88 times.
92 SETFLAG(tmpwarp[wexFlags],warpFlagFORCECONTINUEMUSIC,tmpwarp[wexFlags]&warpFlagFORCERESETMUSIC);
31074 92 TOGGLEFLAG(tmpwarp[wexFlags],warpFlagFORCERESETMUSIC);
31075 92 }
31076 //If we passed the sanity checks, populate the FFCore array and begin the action!
31077
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 92 times.
920 for ( int32_t q = 0; q < wexActive; q++ )
31078 {
31079 828 FFCore.warpex[q] = tmpwarp[q];
31080 828 }
31081 92 FFCore.warpex[wexActive] = 1;
31082 92 break;
31083 }
31084
31085 default:
31086 {
31087 Z_scripterrlog("Array supplied to Hero->WarpEx() is the wrong size!\n The array size was: &d, and valid sizes are [8] and [9].\n",zscript_array_size);
31088 break;
31089 }
31090 }
31091 92 }
31092
31093 ///////////////////////////////
31094 //* SCRIPT ENGINE FUNCTIONS *//
31095 ////////////////////////////////////////////////////////////////////////////
31096
31097 void FFScript::clearRunningItemScripts()
31098 {
31099 //for ( byte q = 0; q < 256; q++ ) runningItemScripts[q] = 0;
31100 }
31101
31102
31103 11195 void FFScript::warpScriptCheck()
31104 {
31105
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 11193 times.
11195 if(get_qr(qr_SCRIPTDRAWSINWARPS))
31106 {
31107 2 FFCore.runWarpScripts(false);
31108 2 FFCore.runWarpScripts(true); //Waitdraw
31109 2 }
31110
3/4
✓ Branch 0 taken 824 times.
✓ Branch 1 taken 10369 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
11193 else if(get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN) && doscript(ScriptType::ScriptedPassiveSubscreen))
31111 {
31112
1/2
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
824 if(DMaps[cur_dmap].passive_sub_script != 0)
31113 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, DMaps[cur_dmap].passive_sub_script, cur_dmap);
31114
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
824 if (waitdraw(ScriptType::ScriptedPassiveSubscreen) && DMaps[cur_dmap].passive_sub_script != 0 && doscript(ScriptType::ScriptedPassiveSubscreen))
31115 {
31116 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, DMaps[cur_dmap].passive_sub_script, cur_dmap);
31117 waitdraw(ScriptType::ScriptedPassiveSubscreen) = false;
31118 }
31119 824 }
31120 11195 }
31121
31122 4 void FFScript::runWarpScripts(bool waitdraw)
31123 {
31124
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if(waitdraw)
31125 {
31126
3/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if ((!( FFCore.system_suspend[susptGLOBALGAME] )) && FFCore.waitdraw(ScriptType::Global, GLOBAL_SCRIPT_GAME))
31127 {
31128 1 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_GAME, GLOBAL_SCRIPT_GAME);
31129 1 FFCore.waitdraw(ScriptType::Global, GLOBAL_SCRIPT_GAME) = false;
31130 1 }
31131
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if ( !FFCore.system_suspend[susptITEMSCRIPTENGINE] )
31132 {
31133 2 FFCore.itemScriptEngineOnWaitdraw();
31134 2 }
31135
2/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2 if ( (!( FFCore.system_suspend[susptHEROACTIVE] )) && FFCore.waitdraw(ScriptType::Hero) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255 )
31136 {
31137 ZScriptVersion::RunScript(ScriptType::Hero, SCRIPT_HERO_ACTIVE);
31138 FFCore.waitdraw(ScriptType::Hero) = false;
31139 }
31140
2/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2 if ( (!( FFCore.system_suspend[susptDMAPSCRIPT] )) && FFCore.waitdraw(ScriptType::DMap) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255 )
31141 {
31142 ZScriptVersion::RunScript(ScriptType::DMap, DMaps[cur_dmap].script,cur_dmap);
31143 FFCore.waitdraw(ScriptType::DMap) = false;
31144 }
31145
4/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 if ( (!( FFCore.system_suspend[susptDMAPSCRIPT] )) && FFCore.waitdraw(ScriptType::ScriptedPassiveSubscreen) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255 )
31146 {
31147 1 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, DMaps[cur_dmap].passive_sub_script,cur_dmap);
31148 1 FFCore.waitdraw(ScriptType::ScriptedPassiveSubscreen) = false;
31149 1 }
31150 //no doscript check here, becauseb of preload? Do we want to write doscript here? -Z 13th July, 2019
31151
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (FFCore.getQuestHeaderInfo(vZelda) >= 0x255 && !FFCore.system_suspend[susptSCREENSCRIPTS])
31152 {
31153 4 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
31154
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2 if (scr->script != 0 && FFCore.waitdraw(ScriptType::Screen, scr->screen) && scr->preloadscript)
31155 {
31156 ZScriptVersion::RunScript(ScriptType::Screen, scr->script, scr->screen);
31157 FFCore.waitdraw(ScriptType::Screen, scr->screen) = 0;
31158 }
31159 2 });
31160 2 }
31161 2 }
31162 else
31163 {
31164
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if ((!( FFCore.system_suspend[susptGLOBALGAME] )) && FFCore.doscript(ScriptType::Global, GLOBAL_SCRIPT_GAME))
31165 {
31166 2 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_GAME, GLOBAL_SCRIPT_GAME);
31167 2 }
31168
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if ( !FFCore.system_suspend[susptITEMSCRIPTENGINE] )
31169 {
31170 2 FFCore.itemScriptEngine();
31171 2 }
31172
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
2 if ((!( FFCore.system_suspend[susptHEROACTIVE] )) && doscript(ScriptType::Hero) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255)
31173 {
31174 2 ZScriptVersion::RunScript(ScriptType::Hero, SCRIPT_HERO_ACTIVE);
31175 2 }
31176
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
2 if ( (!( FFCore.system_suspend[susptDMAPSCRIPT] )) && doscript(ScriptType::DMap) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255 )
31177 {
31178 2 ZScriptVersion::RunScript(ScriptType::DMap, DMaps[cur_dmap].script,cur_dmap);
31179 2 }
31180
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
2 if ( (!( FFCore.system_suspend[susptDMAPSCRIPT] )) && FFCore.doscript(ScriptType::ScriptedPassiveSubscreen) && FFCore.getQuestHeaderInfo(vZelda) >= 0x255 )
31181 {
31182 2 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, DMaps[cur_dmap].passive_sub_script,cur_dmap);
31183 2 }
31184
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (FFCore.getQuestHeaderInfo(vZelda) >= 0x255 && !FFCore.system_suspend[susptSCREENSCRIPTS])
31185 {
31186 4 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
31187
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 if (scr->script != 0 && scr->preloadscript)
31188 {
31189 ZScriptVersion::RunScript(ScriptType::Screen, scr->script, scr->screen);
31190 }
31191 2 });
31192 2 }
31193 }
31194 4 }
31195
31196 34272799 void FFScript::runF6Engine()
31197 {
31198
5/6
✓ Branch 0 taken 34271061 times.
✓ Branch 1 taken 1738 times.
✓ Branch 2 taken 45 times.
✓ Branch 3 taken 34271016 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 45 times.
34272799 if(!Quit && (GameFlags&GAMEFLAG_TRYQUIT) && !(GameFlags&GAMEFLAG_F6SCRIPT_ACTIVE))
31199 {
31200
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
45 if(globalscripts[GLOBAL_SCRIPT_F6]->valid())
31201 {
31202 //Incase this was called mid-another script, store ref data
31203 push_ri();
31204 //
31205 clear_bitmap(f6_menu_buf);
31206 blit(framebuf, f6_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
31207 initZScriptGlobalScript(GLOBAL_SCRIPT_F6);
31208 int32_t openingwipe = black_opening_count;
31209 int32_t openingshape = black_opening_shape;
31210 black_opening_count = 0; //No opening wipe during F6 menu
31211 if(black_opening_shape==bosFADEBLACK) black_fade(0);
31212 GameFlags |= GAMEFLAG_F6SCRIPT_ACTIVE;
31213 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
31214 pause_all_sfx();
31215
31216 auto& data = get_script_engine_data(ScriptType::Global, GLOBAL_SCRIPT_F6);
31217 while (data.doscript)
31218 {
31219 script_drawing_commands.Clear();
31220 load_control_state();
31221 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_F6, GLOBAL_SCRIPT_F6);
31222 if (data.waitdraw)
31223 {
31224 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_F6, GLOBAL_SCRIPT_F6);
31225 data.waitdraw = false;
31226 }
31227 //Draw
31228 clear_bitmap(framebuf);
31229 if( !FFCore.system_suspend[susptCOMBOANIM] ) animate_combos();
31230 doScriptMenuDraws();
31231 //
31232 advanceframe(true,true,false);
31233 if(Quit) break; //Something quit, end script running
31234 }
31235 resume_all_sfx();
31236 script_drawing_commands.Clear();
31237 //script_drawing_commands.push_commands(tmpDrawCommands);
31238 GameFlags &= ~GAMEFLAG_F6SCRIPT_ACTIVE;
31239 //Restore opening wipe
31240 black_opening_count = openingwipe;
31241 black_opening_shape = openingshape;
31242 if(openingshape == bosFADEBLACK)
31243 {
31244 refreshTints();
31245 memcpy(tempblackpal, RAMpal, PAL_SIZE*sizeof(RGB));
31246 }
31247 //Restore script refinfo
31248 pop_ri();
31249 //
31250 if(!Quit)
31251 {
31252 if(!get_qr(qr_NOCONTINUE))
31253 f_Quit(qQUIT);
31254 }
31255 }
31256 45 else f_Quit(qQUIT);
31257 45 zc_readkey(KEY_F6);
31258 45 GameFlags &= ~GAMEFLAG_TRYQUIT;
31259 45 }
31260 34272799 }
31261 33 void FFScript::runOnDeathEngine()
31262 {
31263
2/2
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 2 times.
33 if(!playerscripts[SCRIPT_HERO_DEATH]->valid()) return; //No script to run
31264 2 clear_bitmap(script_menu_buf);
31265 2 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
31266 2 initZScriptHeroScripts();
31267 2 GameFlags |= GAMEFLAG_SCRIPTMENU_ACTIVE;
31268 2 kill_sfx(); //No need to pause/resume; the player is dead.
31269 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
31270
31271 2 auto& data = get_script_engine_data(ScriptType::Hero);
31272
4/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 803 times.
✓ Branch 2 taken 803 times.
✓ Branch 3 taken 2 times.
805 while (data.doscript && !Quit)
31273 {
31274 803 script_drawing_commands.Clear();
31275 803 load_control_state();
31276 803 ZScriptVersion::RunScript(ScriptType::Hero, SCRIPT_HERO_DEATH);
31277
1/2
✓ Branch 0 taken 803 times.
✗ Branch 1 not taken.
803 if (data.waitdraw)
31278 {
31279 ZScriptVersion::RunScript(ScriptType::Hero, SCRIPT_HERO_DEATH);
31280 data.waitdraw = false;
31281 }
31282 //Draw
31283 803 clear_bitmap(framebuf);
31284
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 803 times.
803 if( !FFCore.system_suspend[susptCOMBOANIM] ) animate_combos();
31285 803 doScriptMenuDraws();
31286 //
31287 803 advanceframe(true);
31288 }
31289 2 script_drawing_commands.Clear();
31290 //script_drawing_commands.push_commands(tmpDrawCommands);
31291 2 GameFlags &= ~GAMEFLAG_SCRIPTMENU_ACTIVE;
31292 33 }
31293 416 void FFScript::runOnLaunchEngine()
31294 {
31295
2/2
✓ Branch 0 taken 411 times.
✓ Branch 1 taken 5 times.
416 if(!globalscripts[GLOBAL_SCRIPT_ONLAUNCH]->valid()) return; //No script to run
31296 //Do NOT blit the prior screen to this bitmap; that would be the TITLE SCREEN.
31297 5 clear_to_color(script_menu_buf,BLACK);
31298 5 initZScriptGlobalScript(GLOBAL_SCRIPT_ONLAUNCH);
31299 5 GameFlags |= GAMEFLAG_SCRIPTMENU_ACTIVE;
31300 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
31301
31302 5 auto& data = get_script_engine_data(ScriptType::Global, GLOBAL_SCRIPT_ONLAUNCH);
31303
4/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 5 times.
11 while (data.doscript && !Quit)
31304 {
31305 6 script_drawing_commands.Clear();
31306 6 load_control_state();
31307 6 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_ONLAUNCH, GLOBAL_SCRIPT_ONLAUNCH);
31308
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (data.waitdraw)
31309 {
31310 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_ONLAUNCH, GLOBAL_SCRIPT_ONLAUNCH);
31311 data.waitdraw = false;
31312 }
31313 //Draw
31314 6 clear_bitmap(framebuf);
31315
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if( !FFCore.system_suspend[susptCOMBOANIM] ) animate_combos();
31316
31317 6 doScriptMenuDraws();
31318 //
31319 6 advanceframe(true);
31320 }
31321 5 script_drawing_commands.Clear();
31322 //script_drawing_commands.push_commands(tmpDrawCommands);
31323 5 GameFlags &= ~GAMEFLAG_SCRIPTMENU_ACTIVE;
31324 416 }
31325 10 bool FFScript::runGenericFrozenEngine(const word script, const int32_t *init_data)
31326 {
31327 10 user_genscript& scr = user_genscript::get(script);
31328
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
10 if(script < 1 || script >= NUMSCRIPTSGENERIC) return false;
31329
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(init_data)
31330 {
31331 for(int q = 0; q < 8; ++q)
31332 scr.initd[q] = init_data[q];
31333 }
31334
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!genericscripts[script]->valid()) return false; //No script to run
31335
31336
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(gen_frozen_index >= 400) // Experimentally tested to crash (stack overflow) at 500 for me -Em
31337 {
31338 Z_scripterrlog("Failed to run frozen generic script; too many (%d) frozen scripts running already! Possible infinite recursion?\n", gen_frozen_index);
31339 return false;
31340 }
31341 //Store script refinfo
31342 10 push_ri();
31343 10 int local_i = int(gen_frozen_index++);
31344 10 reset_script_engine_data(ScriptType::GenericFrozen, local_i);
31345 //run script
31346 10 uint32_t fl = GameFlags & GAMEFLAG_SCRIPTMENU_ACTIVE;
31347 10 BITMAP* tmpbuf = script_menu_buf;
31348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(fl)
31349 {
31350 script_menu_buf = create_bitmap_ex(8, framebuf->w, framebuf->h);
31351 }
31352 10 clear_bitmap(script_menu_buf);
31353 10 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
31354 10 GameFlags |= GAMEFLAG_SCRIPTMENU_ACTIVE;
31355 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
31356
4/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1542 times.
✓ Branch 2 taken 1542 times.
✓ Branch 3 taken 10 times.
1552 while(doscript(ScriptType::GenericFrozen, local_i) && !Quit)
31357 {
31358 1542 script_drawing_commands.Clear();
31359 1542 load_control_state();
31360 1542 ZScriptVersion::RunScript(ScriptType::GenericFrozen, script, local_i);
31361 //Draw
31362 1542 clear_bitmap(framebuf);
31363
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1542 times.
1542 if( !FFCore.system_suspend[susptCOMBOANIM] ) animate_combos();
31364 1542 doScriptMenuDraws();
31365 //
31366 1542 advanceframe(true);
31367 }
31368 10 script_drawing_commands.Clear();
31369 //script_drawing_commands.push_commands(tmpDrawCommands);
31370 //clear
31371 10 GameFlags &= ~GAMEFLAG_SCRIPTMENU_ACTIVE;
31372
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(fl)
31373 {
31374 GameFlags |= fl;
31375 destroy_bitmap(script_menu_buf);
31376 script_menu_buf = tmpbuf;
31377 }
31378 10 clear_script_engine_data(ScriptType::GenericFrozen, local_i);
31379 10 --gen_frozen_index;
31380 //Restore script refinfo
31381 10 pop_ri();
31382 10 return true;
31383 10 }
31384
31385 1398 bool FFScript::runScriptedActiveSusbcreen()
31386 {
31387 1398 word activesubscript = DMaps[cur_dmap].active_sub_script;
31388
3/4
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 1357 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 41 times.
1398 if(!activesubscript || !dmapscripts[activesubscript]->valid()) return false; //No script to run
31389 41 word passivesubscript = DMaps[cur_dmap].passive_sub_script;
31390 41 word dmapactivescript = DMaps[cur_dmap].script;
31391 41 clear_bitmap(script_menu_buf);
31392 41 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
31393 41 initZScriptScriptedActiveSubscreen();
31394 41 GameFlags |= GAMEFLAG_SCRIPTMENU_ACTIVE;
31395 41 word script_dmap = cur_dmap;
31396 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
31397 41 pause_all_sfx();
31398 41 auto& data = get_script_engine_data(ScriptType::ScriptedActiveSubscreen);
31399
4/4
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 6772 times.
✓ Branch 2 taken 6772 times.
✓ Branch 3 taken 41 times.
6813 while (data.doscript && !Quit)
31400 {
31401 6772 script_drawing_commands.Clear();
31402 6772 load_control_state();
31403
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 6772 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
6772 if(get_qr(qr_DMAP_ACTIVE_RUNS_DURING_ACTIVE_SUBSCRIPT) && DMaps[script_dmap].script != 0 && doscript(ScriptType::DMap))
31404 {
31405 ZScriptVersion::RunScript(ScriptType::DMap, dmapactivescript, script_dmap);
31406 }
31407
4/6
✓ Branch 0 taken 140 times.
✓ Branch 1 taken 6632 times.
✓ Branch 2 taken 140 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 140 times.
6772 if(get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_DURING_ACTIVE_SUBSCRIPT)!=0 && DMaps[script_dmap].passive_sub_script != 0 && FFCore.doscript(ScriptType::ScriptedPassiveSubscreen))
31408 {
31409 140 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, passivesubscript, script_dmap);
31410 140 }
31411 6772 ZScriptVersion::RunScript(ScriptType::ScriptedActiveSubscreen, activesubscript, script_dmap);
31412
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6772 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6772 if(waitdraw(ScriptType::DMap) && (get_qr(qr_DMAP_ACTIVE_RUNS_DURING_ACTIVE_SUBSCRIPT) && DMaps[script_dmap].script != 0 && doscript(ScriptType::DMap)))
31413 {
31414 ZScriptVersion::RunScript(ScriptType::DMap, dmapactivescript, script_dmap);
31415 waitdraw(ScriptType::DMap) = false;
31416 }
31417
5/8
✓ Branch 0 taken 139 times.
✓ Branch 1 taken 6633 times.
✓ Branch 2 taken 139 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 139 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 139 times.
6772 if(waitdraw(ScriptType::ScriptedPassiveSubscreen) && (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_DURING_ACTIVE_SUBSCRIPT)!=0 && DMaps[script_dmap].passive_sub_script != 0 && FFCore.doscript(ScriptType::ScriptedPassiveSubscreen)))
31418 {
31419 139 ZScriptVersion::RunScript(ScriptType::ScriptedPassiveSubscreen, passivesubscript, script_dmap);
31420 139 waitdraw(ScriptType::ScriptedPassiveSubscreen) = false;
31421 139 }
31422
3/4
✓ Branch 0 taken 5472 times.
✓ Branch 1 taken 1300 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5472 times.
6772 if (data.waitdraw && data.doscript)
31423 {
31424 5472 ZScriptVersion::RunScript(ScriptType::ScriptedActiveSubscreen, activesubscript, script_dmap);
31425 5472 data.waitdraw = false;
31426 5472 }
31427 //Draw
31428 6772 clear_bitmap(framebuf);
31429
2/4
✓ Branch 0 taken 6772 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6772 times.
6772 if(cur_dmap == script_dmap && ( !FFCore.system_suspend[susptCOMBOANIM] ) ) animate_combos();
31430 6772 doScriptMenuDraws();
31431 //
31432 6772 advanceframe(true);
31433 //Handle warps; run game_loop once!
31434
1/2
✓ Branch 0 taken 6772 times.
✗ Branch 1 not taken.
6772 if(cur_dmap != script_dmap)
31435 {
31436 activesubscript = DMaps[cur_dmap].active_sub_script;
31437 if(!activesubscript || !dmapscripts[activesubscript]->valid()) return true; //No script to run
31438 passivesubscript = DMaps[cur_dmap].passive_sub_script;
31439 dmapactivescript = DMaps[cur_dmap].script;
31440 script_dmap = cur_dmap;
31441 //Reset the background image
31442 game_loop();
31443 clear_bitmap(script_menu_buf);
31444 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
31445 //Now loop without advancing frame, so that the subscreen script can draw immediately.
31446 }
31447 }
31448 41 resume_all_sfx();
31449 41 script_drawing_commands.Clear();
31450 //script_drawing_commands.push_commands(tmpDrawCommands);
31451 41 GameFlags &= ~GAMEFLAG_SCRIPTMENU_ACTIVE;
31452 41 GameFlags |= GAMEFLAG_RESET_GAME_LOOP;
31453 41 return true;
31454 1398 }
31455 1078 bool FFScript::runOnMapScriptEngine()
31456 {
31457 1078 word onmap_script = DMaps[cur_dmap].onmap_script;
31458
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1075 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
1078 if(!onmap_script || !dmapscripts[onmap_script]->valid()) return false; //No script to run
31459 3 clear_bitmap(script_menu_buf);
31460 3 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
31461 3 initZScriptOnMapScript();
31462 3 GameFlags |= GAMEFLAG_SCRIPTMENU_ACTIVE;
31463 3 word script_dmap = cur_dmap;
31464 //auto tmpDrawCommands = script_drawing_commands.pop_commands();
31465 3 pause_all_sfx();
31466
31467 3 auto& data = get_script_engine_data(ScriptType::OnMap);
31468
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 114 times.
✓ Branch 2 taken 114 times.
✓ Branch 3 taken 3 times.
117 while (data.doscript && !Quit)
31469 {
31470 114 script_drawing_commands.Clear();
31471 114 load_control_state();
31472 114 ZScriptVersion::RunScript(ScriptType::OnMap, onmap_script, script_dmap);
31473
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
114 if (data.waitdraw && data.doscript)
31474 {
31475 ZScriptVersion::RunScript(ScriptType::OnMap, onmap_script, script_dmap);
31476 data.waitdraw = false;
31477 }
31478 //Draw
31479 114 clear_bitmap(framebuf);
31480
2/4
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 114 times.
114 if(cur_dmap == script_dmap && ( !FFCore.system_suspend[susptCOMBOANIM] ) ) animate_combos();
31481 114 doScriptMenuDraws();
31482 //
31483 114 advanceframe(true);
31484 //Handle warps; run game_loop once!
31485
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 if(cur_dmap != script_dmap)
31486 {
31487 onmap_script = DMaps[cur_dmap].onmap_script;
31488 if(!onmap_script || !dmapscripts[onmap_script]->valid()) return true; //No script to run
31489 script_dmap = cur_dmap;
31490 //Reset the background image
31491 game_loop();
31492 clear_bitmap(script_menu_buf);
31493 blit(framebuf, script_menu_buf, 0, 0, 0, 0, framebuf->w, framebuf->h);
31494 //Now loop without advancing frame, so that the subscreen script can draw immediately.
31495 }
31496 }
31497 3 resume_all_sfx();
31498 3 script_drawing_commands.Clear();
31499 //script_drawing_commands.push_commands(tmpDrawCommands);
31500 3 GameFlags &= ~GAMEFLAG_SCRIPTMENU_ACTIVE;
31501 3 GameFlags |= GAMEFLAG_RESET_GAME_LOOP;
31502 3 return true;
31503 1078 }
31504
31505 9237 void FFScript::doScriptMenuDraws()
31506 {
31507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9237 times.
9237 BITMAP* menu_buf = ((GameFlags & GAMEFLAG_F6SCRIPT_ACTIVE) != 0) ? f6_menu_buf : script_menu_buf;
31508 9237 blit(menu_buf, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
31509 //Script draws
31510 9237 do_script_draws(framebuf, origin_scr, 0, playing_field_offset);
31511 9237 }
31512
31513 266 void FFScript::runOnSaveEngine()
31514 {
31515
1/2
✓ Branch 0 taken 266 times.
✗ Branch 1 not taken.
266 if(globalscripts[GLOBAL_SCRIPT_ONSAVE]->valid())
31516 {
31517 push_ri();
31518 //Prevent getting here via Quit from causing a forced-script-quit after 1000 commands!
31519 int32_t tQuit = Quit;
31520 Quit = 0;
31521 //
31522 initZScriptGlobalScript(GLOBAL_SCRIPT_ONSAVE);
31523 ZScriptVersion::RunScript(ScriptType::Global, GLOBAL_SCRIPT_ONSAVE, GLOBAL_SCRIPT_ONSAVE);
31524 //
31525 pop_ri();
31526 Quit = tQuit;
31527 }
31528 266 }
31529
31530 15636726 bool FFScript::itemScriptEngine()
31531 {
31532
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15636726 times.
15636726 if ( FFCore.system_suspend[susptITEMSCRIPTENGINE] ) return false;
31533
2/2
✓ Branch 0 taken 4003001856 times.
✓ Branch 1 taken 15636726 times.
4018638582 for ( int32_t q = 0; q < MAXITEMS; q++ )
31534 {
31535
31536
3/4
✓ Branch 0 taken 29532190 times.
✓ Branch 1 taken 3973469666 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 29532190 times.
4003001856 if ( itemsbuf[q].script <= 0 || itemsbuf[q].script > NUMSCRIPTITEM ) continue; // > NUMSCRIPTITEM as someone could force an invaid script slot!
31537
31538 29532190 auto& data = get_script_engine_data(ScriptType::Item, q);
31539
2/2
✓ Branch 0 taken 14167 times.
✓ Branch 1 taken 29518023 times.
29532190 if ( data.doscript < 1 ) continue;
31540
31541 //Passive items
31542
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14167 times.
14167 if (((itemsbuf[q].flags&item_passive_script)))
31543 {
31544 if(game->item[q] && (get_qr(qr_ITEMSCRIPTSKEEPRUNNING)))
31545 {
31546 if(get_qr(qr_PASSIVE_ITEM_SCRIPT_ONLY_HIGHEST)
31547 && current_item(itemsbuf[q].family) > itemsbuf[q].fam_type)
31548 data.doscript = 0;
31549 else ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q&0xFFF);
31550 if(!data.doscript) //Item script ended. Clear the data, if any remains.
31551 {
31552 data.ref.Clear();
31553 data.initialized = false;
31554 data.waitdraw = false;
31555 FFScript::deallocateAllScriptOwned(ScriptType::Item, q);
31556 }
31557 }
31558 }
31559 else
31560 {
31561
31562 //Normal Items
31563 /*! What happens here: When an item script is first run by the user using that utem, the script runs for one frame.
31564 After executing RunScript(), item_doscript is set to '1' in hero.cpp.
31565 If the quest allows the item to continue running, the itemScriptEngine() function ignores running the
31566 same item script (again) that frame, and insteads increments item_doscript to '2'.
31567 If item_doscript == 2, then we know we are on the second frame, and we run it perpetually.
31568 If the QR to enable item scripts to run for more than one frame is not enabled, then item_doscript is set to '0'.
31569 If the item flag 'PERPETUAL SCRIPT' is enabled, then we ignore the lack of item_doscript==2.
31570 This allows passive item scripts to function.
31571 */
31572
31573 14167 auto& data = get_script_engine_data(ScriptType::Item, q);
31574
31575
2/2
✓ Branch 0 taken 662 times.
✓ Branch 1 taken 13505 times.
14167 if ( data.doscript == 1 ) // FIrst frame, normally set in hero.cpp
31576 {
31577
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 662 times.
662 if ( get_qr(qr_ITEMSCRIPTSKEEPRUNNING) )
31578 {
31579 662 data.doscript = 2;
31580 662 }
31581 662 }
31582
1/2
✓ Branch 0 taken 13505 times.
✗ Branch 1 not taken.
13505 else if (data.doscript == 2) //Second frame and later, if scripts continue to run.
31583 {
31584 13505 ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q&0xFFF);
31585 13505 }
31586 else if (data.doscript == 3) //Run via itemdata->RunScript
31587 {
31588 if ( (get_qr(qr_ITEMSCRIPTSKEEPRUNNING)) )
31589 {
31590 data.doscript = 2; //Reduce to normal run status
31591 }
31592 else
31593 {
31594 ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q & 0xFFF);
31595 data.doscript = 0;
31596 }
31597 }
31598 else if(data.doscript==4) //Item set itself false, kill script and clear data here
31599 {
31600 data.doscript = 0;
31601 }
31602
2/2
✓ Branch 0 taken 13490 times.
✓ Branch 1 taken 677 times.
14167 if(data.doscript==0) //Item script ended. Clear the data, if any remains.
31603 {
31604 677 data.ref.Clear();
31605 677 data.initialized = false;
31606 677 data.waitdraw = false;
31607 677 FFScript::deallocateAllScriptOwned(ScriptType::Item, q);
31608 677 }
31609 }
31610 14167 }
31611 15636726 return false;
31612 15636726 }
31613
31614 16125924 bool FFScript::itemScriptEngineOnWaitdraw()
31615 {
31616
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16125924 times.
16125924 if ( FFCore.system_suspend[susptITEMSCRIPTENGINE] ) return false;
31617
2/2
✓ Branch 0 taken 4128236544 times.
✓ Branch 1 taken 16125924 times.
4144362468 for ( int32_t q = 0; q < MAXITEMS; q++ )
31618 {
31619
3/4
✓ Branch 0 taken 31392395 times.
✓ Branch 1 taken 4096844149 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 31392395 times.
4128236544 if ( itemsbuf[q].script <= 0 || itemsbuf[q].script > NUMSCRIPTITEM ) continue; // > NUMSCRIPTITEM as someone could force an invaid script slot!
31620
31621 31392395 auto& data = get_script_engine_data(ScriptType::Item, q);
31622
31623
2/2
✓ Branch 0 taken 13491 times.
✓ Branch 1 taken 31378904 times.
31392395 if ( data.doscript < 1 ) continue;
31624
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13491 times.
13491 if (!data.waitdraw) continue;
31625 else data.waitdraw = false;
31626
31627 /*! What happens here: When an item script is first run by the user using that utem, the script runs for one frame.
31628 After executing RunScript(), item_doscript is set to '1' in hero.cpp.
31629 If the quest allows the item to continue running, the itemScriptEngine() function ignores running the
31630 same item script (again) that frame, and insteads increments item_doscript to '2'.
31631 If item_doscript == 2, then we know we are on the second frame, and we run it perpetually.
31632 If the QR to enable item scripts to run for more than one frame is not enabled, then item_doscript is set to '0'.
31633 If the item flag 'PERPETUAL SCRIPT' is enabled, then we ignore the lack of item_doscript==2.
31634 This allows passive item scripts to function.
31635 */
31636 //Passive items
31637 if ((itemsbuf[q].flags&item_passive_script))
31638 {
31639 if(game->item[q] && (get_qr(qr_ITEMSCRIPTSKEEPRUNNING)))
31640 {
31641 if(get_qr(qr_PASSIVE_ITEM_SCRIPT_ONLY_HIGHEST)
31642 && current_item(itemsbuf[q].family) > itemsbuf[q].fam_type)
31643 data.doscript = 0;
31644 else ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q&0xFFF);
31645 if(!data.doscript) //Item script ended. Clear the data, if any remains.
31646 {
31647 data.ref.Clear();
31648 data.initialized = false;
31649 data.waitdraw = false;
31650 FFScript::deallocateAllScriptOwned(ScriptType::Item, q);
31651 }
31652 }
31653 }
31654 else
31655 {
31656 //Normal items
31657 if ( data.doscript == 1 ) // FIrst frame, normally set in hero.cpp
31658 {
31659 if ( get_qr(qr_ITEMSCRIPTSKEEPRUNNING) )
31660 {
31661 data.doscript = 2;
31662 }
31663 else data.doscript = 0;
31664 }
31665 else if (data.doscript == 2) //Second frame and later, if scripts continue to run.
31666 {
31667 ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q&0xFFF);
31668 }
31669 else if (data.doscript == 3) //Run via itemdata->RunScript
31670 {
31671 if ( (get_qr(qr_ITEMSCRIPTSKEEPRUNNING)) )
31672 {
31673 data.doscript = 2; //Reduce to normal run status
31674 }
31675 else
31676 {
31677 ZScriptVersion::RunScript(ScriptType::Item, itemsbuf[q].script, q & 0xFFF);
31678 data.doscript = 0;
31679 }
31680 }
31681 else if(data.doscript==4) //Item set itself false, kill script and clear data here.
31682 {
31683 data.doscript = 0;
31684 }
31685 if(!data.doscript) //Item script ended. Clear the data, if any remains.
31686 {
31687 data.ref.Clear();
31688 data.initialized = false;
31689 data.waitdraw = false;
31690 FFScript::deallocateAllScriptOwned(ScriptType::Item, q);
31691 }
31692 }
31693 }
31694 16125924 return false;
31695 16125924 }
31696 14487557 void FFScript::npcScriptEngineOnWaitdraw()
31697 {
31698
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14487557 times.
14487557 if ( FFCore.system_suspend[susptNPCSCRIPTS] ) return;
31699 14487557 guys.run_script(MODE_WAITDRAW);
31700 14487557 }
31701
31702 14025776 void FFScript::eweaponScriptEngine()
31703 {
31704
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14025776 times.
14025776 if ( FFCore.system_suspend[susptEWEAPONSCRIPTS] ) return;
31705 14025776 Ewpns.run_script(MODE_NORMAL);
31706 14025776 }
31707
31708 14487557 void FFScript::lweaponScriptEngineOnWaitdraw()
31709 {
31710
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14487557 times.
14487557 if ( FFCore.system_suspend[susptLWEAPONSCRIPTS] ) return;
31711 14487557 Lwpns.run_script(MODE_WAITDRAW);
31712 14487557 }
31713
31714 14515083 void FFScript::eweaponScriptEngineOnWaitdraw()
31715 {
31716
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 14515073 times.
14515083 if ( FFCore.system_suspend[susptEWEAPONSCRIPTS] ) return;
31717 14515073 Ewpns.run_script(MODE_WAITDRAW);
31718 14515083 }
31719
31720 14028402 void FFScript::itemSpriteScriptEngine()
31721 {
31722
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14028402 times.
14028402 if ( FFCore.system_suspend[susptITEMSPRITESCRIPTS] ) return;
31723 14028402 items.run_script(MODE_NORMAL);
31724 14028402 }
31725
31726 14517601 void FFScript::itemSpriteScriptEngineOnWaitdraw()
31727 {
31728
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14517601 times.
14517601 if ( FFCore.system_suspend[susptITEMSPRITESCRIPTS] ) return;
31729 14517601 items.run_script(MODE_WAITDRAW);
31730 14517601 }
31731
31732
31733 15 int32_t FFScript::getTime(int32_t type)
31734 {
31735 //struct tm *tm_struct = localtime(time(NULL));
31736 struct tm * tm_struct;
31737 time_t sysRTC;
31738 15 time (&sysRTC);
31739 15 tm_struct = localtime (&sysRTC);
31740 15 int32_t rval = -1;
31741
31742
5/10
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
15 switch(type)
31743 {
31744 case curyear:
31745 {
31746 //Year format starts at 1900, yeat
31747 //A raw read of '2018' would be '118', so we add 1900 to it to derive the actual year.
31748 3 rval = tm_struct->tm_year + 1900; break;
31749
31750 }
31751 case curmonth:
31752 {
31753 //Months start at 0, but we want 1->12
31754 rval = tm_struct->tm_mon +1; break;
31755 }
31756 case curday_month:
31757 {
31758 rval = tm_struct->tm_mday; break;
31759 }
31760 case curday_week:
31761 {
31762 //It seems that weekdays are a value range of 1 to 7.
31763 rval = tm_struct->tm_wday; break;
31764 }
31765 case curhour:
31766 {
31767 3 rval = tm_struct->tm_hour; break;
31768 }
31769 case curminute:
31770 {
31771 3 rval = tm_struct->tm_min; break;
31772 }
31773 case cursecond:
31774 {
31775 3 rval = tm_struct->tm_sec; break;
31776 }
31777 case curdayyear:
31778 {
31779 //The day (n/365) out of the entire year.
31780 3 rval = tm_struct->tm_yday; break;
31781 }
31782 case curDST:
31783 {
31784 //Returns if the user is in a Time Zone with Daylight TIme of some sort.
31785 //View the time.h docs for the actual values of this struct element.
31786 rval = tm_struct->tm_isdst;; break;
31787 }
31788 default:
31789 {
31790 al_trace("Invalid category passed to GetSystemTime(%d)\n",type);
31791 rval = -1; break;
31792 }
31793
31794 }
31795 15 return rval;
31796 }
31797
31798 10 void FFScript::do_lweapon_delete()
31799 {
31800
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(0!=(s=checkLWpn(ri->lwpn)))
31801 {
31802
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(s==Hero.lift_wpn)
31803 {
31804 delete s;
31805 Hero.lift_wpn = nullptr;
31806 }
31807 10 else Lwpns.del(s);
31808 10 }
31809 10 }
31810
31811 46 void FFScript::do_eweapon_delete()
31812 {
31813
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if(0!=(s=checkEWpn(ri->ewpn)))
31814 {
31815 46 Ewpns.del(s);
31816 46 }
31817 46 }
31818
31819 1077 void FFScript::updateIncludePaths()
31820 {
31821 1077 includePaths.clear();
31822 1077 int32_t pos = 0;
31823
2/2
✓ Branch 0 taken 3723 times.
✓ Branch 1 taken 1077 times.
4800 for ( int32_t q = 0; includePathString[pos]; ++q )
31824 {
31825 3723 int32_t dest = 0;
31826 3723 char buf[2048] = {0};
31827
4/4
✓ Branch 0 taken 3641 times.
✓ Branch 1 taken 76196 times.
✓ Branch 2 taken 76114 times.
✓ Branch 3 taken 3723 times.
79837 while(includePathString[pos] != ';' && includePathString[pos])
31828 {
31829 76114 buf[dest] = includePathString[pos];
31830 76114 ++pos;
31831 76114 ++dest;
31832 }
31833 3723 ++pos;
31834
1/2
✓ Branch 0 taken 3723 times.
✗ Branch 1 not taken.
3723 std::string str(buf);
31835
1/2
✓ Branch 0 taken 3723 times.
✗ Branch 1 not taken.
3723 includePaths.push_back(str);
31836 3723 }
31837 1077 }
31838
31839 1077 void FFScript::initIncludePaths()
31840 {
31841 1077 memset(includePathString,0,sizeof(includePathString));
31842 1077 FILE* f = fopen("includepaths.txt", "r");
31843
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 995 times.
1077 if(f)
31844 {
31845 82 int32_t pos = 0;
31846 int32_t c;
31847 82 do
31848 {
31849 52972 c = fgetc(f);
31850
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 52890 times.
52972 if(c!=EOF)
31851 52890 includePathString[pos++] = c;
31852
2/2
✓ Branch 0 taken 52890 times.
✓ Branch 1 taken 82 times.
105944 }
31853
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 52890 times.
52972 while(c!=EOF && pos<MAX_INCLUDE_PATH_CHARS);
31854
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(pos<MAX_INCLUDE_PATH_CHARS)
31855 82 includePathString[pos] = '\0';
31856 82 includePathString[MAX_INCLUDE_PATH_CHARS-1] = '\0';
31857 82 fclose(f);
31858 82 }
31859 995 else strcpy(includePathString, "include/;headers/;scripts/;");
31860 1077 al_trace("Full path string is: ");
31861 1077 safe_al_trace(includePathString);
31862 1077 al_trace("\n");
31863 1077 updateIncludePaths();
31864
31865
2/2
✓ Branch 0 taken 3723 times.
✓ Branch 1 taken 1077 times.
4800 for ( size_t q = 0; q < includePaths.size(); ++q )
31866 {
31867 3723 al_trace("Include path %zu: ",q);
31868 3723 safe_al_trace(includePaths.at(q));
31869 3723 al_trace("\n");
31870 3723 }
31871 1077 }
31872
31873 10 bool FFScript::checkExtension(std::string &filename, const std::string &extension)
31874 //inline bool checkExtension(std::string filename, std::string extension)
31875 {
31876 10 int32_t dot = filename.find_last_of(".");
31877
3/10
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
10 std::string exten = (dot == std::string::npos ? "" : filename.substr(dot, filename.length() - dot));
31878 10 return exten == extension;
31879 10 }
31880
31881
31882 void FFScript::do_loadgamestructs(const bool v, const bool v2)
31883 {
31884 int32_t arrayptr = SH::get_arg(sarg1, v);
31885 int32_t section_id = SH::get_arg(sarg2, v2) / 10000;
31886 //Bitwise OR sections together
31887 string strA;
31888 ArrayH::getString(arrayptr, strA, 256);
31889 int32_t temp_sram_flags = section_id; int32_t sram_version = 0;
31890
31891 if ( FFCore.checkExtension(strA, ".zcsram") )
31892 {
31893 PACKFILE *f = pack_fopen_password(strA.c_str(),F_READ, "");
31894 if (f)
31895 {
31896 p_igetl(&sram_version,f);
31897 p_igetl(&section_id,f);
31898 if ( sram_version > SRAM_VERSION ) //file version is greater than programme current version.
31899 {
31900 Z_scripterrlog("SRAM Version is from a version of ZC newer than the running version and cannot be loaded.\n");
31901 return;
31902 }
31903 if ( section_id != temp_sram_flags )
31904 {
31905 Z_scripterrlog("Reading an SRAM file with a section flag mismatch!\nThe file section flags are (%d) and the specified flagset is (%d).\nThis may cause errors!\n", section_id, temp_sram_flags);
31906 }
31907
31908 if ( !section_id || section_id&svGUYS ) FFCore.read_enemies(f,sram_version);
31909 if ( !section_id || section_id&svITEMS )FFCore.read_items(f,sram_version);
31910 if ( !section_id || section_id&svWEAPONS ) FFCore.read_weaponsprtites(f,sram_version);
31911 if ( !section_id || section_id&svCOMBOS )
31912 {
31913 reset_all_combo_animations();
31914 FFCore.read_combos(f,sram_version);
31915 }
31916 if ( !section_id || section_id&svDMAPS ) FFCore.read_dmaps(f,sram_version);
31917 if ( !section_id || section_id&svMAPSCR ) FFCore.read_mapscreens(f,sram_version);
31918 pack_fclose(f);
31919
31920 set_register(sarg1, 10000);
31921 }
31922 else
31923 {
31924 Z_scripterrlog("FFCore.do_loadgamestructs could not read packfile!");
31925 set_register(sarg1, -10000);
31926 }
31927 }
31928 else
31929 {
31930 Z_scripterrlog("Tried to read a .zcsram file, but the file lacked the ..zcsram extension!\n");
31931 set_register(sarg1, -20000);
31932
31933 }
31934 }
31935
31936 110 void FFScript::do_savegamestructs(const bool v, const bool v2)
31937 {
31938 110 int32_t arrayptr = SH::get_arg(sarg1, v);
31939 110 int32_t section_id = SH::get_arg(sarg2, v2) / 10000;
31940 //Bitwise OR sections together
31941 110 string strA;
31942
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 100 times.
110 ArrayH::getString(arrayptr, strA, 256);
31943 10 int32_t cycles = 0;
31944
31945
3/6
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 if ( FFCore.checkExtension(strA, ".zcsram") )
31946 {
31947
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 PACKFILE *f = pack_fopen_password(strA.c_str(),F_WRITE, "");
31948
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (f)
31949 {
31950
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 p_iputl(SRAM_VERSION,f);
31951
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 p_iputl(section_id,f);
31952
31953
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
10 if ( !section_id || section_id&svGUYS ) FFCore.write_enemies(f,SRAM_VERSION);
31954 if ( !section_id || section_id&svITEMS ) FFCore.write_items(f,SRAM_VERSION);
31955 if ( !section_id || section_id&svWEAPONS ) FFCore.write_weaponsprtites(f,SRAM_VERSION);
31956 if ( !section_id || section_id&svCOMBOS )
31957 {
31958
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 reset_all_combo_animations();
31959 FFCore.write_combos(f,SRAM_VERSION);
31960 }
31961 if ( !section_id || section_id&svDMAPS ) FFCore.write_dmaps(f,SRAM_VERSION);
31962 if ( !section_id || section_id&svMAPSCR ) FFCore.write_mapscreens(f,SRAM_VERSION);
31963
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 pack_fclose(f);
31964
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 set_register(sarg1, 10000);
31965 10 }
31966 else
31967 {
31968 Z_scripterrlog("FFCore.do_loadgamestructs could not read packfile!");
31969 set_register(sarg1, -10000);
31970 }
31971 10 }
31972 else
31973 {
31974 Z_scripterrlog("Tried to write a .zcsram file, but the file lacked the ..zcsram extension!\n");
31975 set_register(sarg1, -20000);
31976 }
31977 210 }
31978
31979 2541 void FFScript::do_strcmp()
31980 {
31981 2541 int32_t arrayptr_a = ri->d[rINDEX];
31982 2541 int32_t arrayptr_b = ri->d[rINDEX2];
31983 2541 string strA;
31984 2541 string strB;
31985
1/2
✓ Branch 0 taken 2541 times.
✗ Branch 1 not taken.
2541 ArrayH::getString(arrayptr_a, strA);
31986
1/2
✓ Branch 0 taken 2541 times.
✗ Branch 1 not taken.
2541 ArrayH::getString(arrayptr_b, strB);
31987
1/2
✓ Branch 0 taken 2541 times.
✗ Branch 1 not taken.
2541 set_register(sarg1, (strcmp(strA.c_str(), strB.c_str()) * 10000));
31988 2541 }
31989
31990 void FFScript::do_stricmp()
31991 {
31992 int32_t arrayptr_a = ri->d[rINDEX];
31993 int32_t arrayptr_b = ri->d[rINDEX2];
31994 string strA;
31995 string strB;
31996 ArrayH::getString(arrayptr_a, strA);
31997 ArrayH::getString(arrayptr_b, strB);
31998 set_register(sarg1, (stricmp(strA.c_str(), strB.c_str()) * 10000));
31999 }
32000
32001 1 void FFScript::do_LowerToUpper(const bool v)
32002 {
32003 1 int32_t arrayptr_a = get_register(sarg1);
32004 1 string strA;
32005
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ArrayH::getString(arrayptr_a, strA);
32006
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
6 for (char& c : strA)
32007 5 c = std::toupper(c);
32008
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ArrayH::setArray(arrayptr_a, strA);
32009
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 set_register(sarg1, 10000); // used to return 0 if string was empty.
32010 1 }
32011
32012 void FFScript::do_UpperToLower(const bool v)
32013 {
32014 int32_t arrayptr_a = get_register(sarg1);
32015 string strA;
32016 ArrayH::getString(arrayptr_a, strA);
32017 for (char& c : strA)
32018 c = std::tolower(c);
32019 ArrayH::setArray(arrayptr_a, strA);
32020 set_register(sarg1, 10000); // used to return 0 if string was empty.
32021 }
32022
32023 void FFScript::do_getnpcscript()
32024 {
32025 do_get_script_index_by_name(name_to_slot_index_npcmap);
32026 }
32027
32028 void FFScript::do_getcomboscript()
32029 {
32030 do_get_script_index_by_name(name_to_slot_index_comboscriptmap);
32031 }
32032
32033 137111 void FFScript::do_getgenericscript()
32034 {
32035 137111 do_get_script_index_by_name(name_to_slot_index_genericmap);
32036 137111 }
32037
32038 1707 void FFScript::do_getlweaponscript()
32039 {
32040 1707 do_get_script_index_by_name(name_to_slot_index_lwpnmap);
32041 1707 }
32042 1664 void FFScript::do_geteweaponscript()
32043 {
32044 1664 do_get_script_index_by_name(name_to_slot_index_ewpnmap);
32045 1664 }
32046 void FFScript::do_getheroscript()
32047 {
32048 do_get_script_index_by_name(name_to_slot_index_playermap);
32049 }
32050 void FFScript::do_getglobalscript()
32051 {
32052 do_get_script_index_by_name(name_to_slot_index_globalmap);
32053 }
32054 105 void FFScript::do_getdmapscript()
32055 {
32056 105 do_get_script_index_by_name(name_to_slot_index_dmapmap);
32057 105 }
32058 void FFScript::do_getscreenscript()
32059 {
32060 do_get_script_index_by_name(name_to_slot_index_screenmap);
32061 }
32062 31 void FFScript::do_getitemspritescript()
32063 {
32064 31 do_get_script_index_by_name(name_to_slot_index_itemspritemap);
32065 31 }
32066 //Not assigned to slots at present. If they ever are, then this would get the id of any script (any type) by name. -Z
32067 void FFScript::do_getuntypedscript()
32068 {
32069 set_register(sarg1, 0);
32070 }
32071 void FFScript::do_getsubscreenscript()
32072 {
32073 do_get_script_index_by_name(name_to_slot_index_subscreenmap);
32074 }
32075 void FFScript::do_getnpcbyname()
32076 {
32077 int32_t arrayptr = get_register(sarg1);
32078 string the_string;
32079 int32_t num = -1;
32080 ArrayH::getString(arrayptr, the_string, 256); //What is the max length of a script identifier?
32081
32082 for(int32_t q = 0; q < MAXNPCS; q++)
32083 {
32084 if(!(strcmp(the_string.c_str(), guy_string[q])))
32085 {
32086 num = q;
32087 break;
32088 }
32089 }
32090 set_register(sarg1, (num * 10000));
32091 }
32092 void FFScript::do_getitembyname()
32093 {
32094 int32_t arrayptr = get_register(sarg1);
32095 string the_string;
32096 int32_t num = -1;
32097 ArrayH::getString(arrayptr, the_string, 256); //What is the max length of a script identifier?
32098
32099 for(int32_t q = 0; q < MAXNPCS; q++)
32100 {
32101 if(!(strcmp(the_string.c_str(), item_string[q])))
32102 {
32103 num = q;
32104 break;
32105 }
32106 }
32107 set_register(sarg1, (num * 10000));
32108 }
32109 void FFScript::do_getcombobyname()
32110 {
32111 int32_t arrayptr = get_register(sarg1);
32112 string the_string;
32113 int32_t num = -1;
32114 ArrayH::getString(arrayptr, the_string, 256);
32115
32116 if (!the_string.empty())
32117 {
32118 for(int32_t q = 0; q < MAXCOMBOS; q++)
32119 {
32120 if (the_string == combobuf[q].label)
32121 {
32122 num = q;
32123 break;
32124 }
32125 }
32126 }
32127 set_register(sarg1, (num * 10000));
32128 }
32129 void FFScript::do_getdmapbyname()
32130 {
32131 int32_t arrayptr = get_register(sarg1);
32132 string the_string;
32133 int32_t num = -1;
32134 ArrayH::getString(arrayptr, the_string, 256); //What is the max length of a script identifier?
32135
32136 for(int32_t q = 0; q < MAXDMAPS; q++)
32137 {
32138 if(!(strcmp(the_string.c_str(), DMaps[q].name)))
32139 {
32140 num = q;
32141 break;
32142 }
32143 }
32144 set_register(sarg1, (num * 10000));
32145 }
32146
32147 ////////////////////////
32148 /// String Utilities ///
32149 ////////////////////////
32150 void FFScript::do_ConvertCase(const bool v)
32151 {
32152 int32_t arrayptr_a = get_register(sarg1);
32153 string strA;
32154 ArrayH::getString(arrayptr_a, strA);
32155 for (char& c : strA)
32156 {
32157 if (c < 'a')
32158 c += 32 * (c >= 'A' && c <= 'Z');
32159 else
32160 c -= 32 * (c >= 'a' && c <= 'z');
32161 }
32162 ArrayH::setArray(arrayptr_a, strA);
32163 set_register(sarg1, (10000)); // used to return 0 if string was empty.
32164 }
32165
32166 void FFScript::do_xlen(const bool v)
32167 {
32168 //not implemented, xlen not found
32169 int32_t arrayptr = (SH::get_arg(sarg2, v));
32170 string str;
32171 ArrayH::getString(arrayptr, str);
32172 }
32173
32174 void FFScript::do_xtoi(const bool v)
32175 {
32176 int32_t arrayptr = (SH::get_arg(sarg2, v));
32177 string str;
32178 ArrayH::getString(arrayptr, str);
32179 double val = zc_xtoi(const_cast<char*>(str.c_str()));
32180 set_register(sarg1, (int32_t)(val) * 10000);
32181 }
32182 void FFScript::do_xtoi2()
32183 {
32184 int32_t arrayptr_a = ri->d[rINDEX];
32185 string strA;
32186 ArrayH::getString(arrayptr_a, strA);
32187 set_register(sarg1, (zc_xtoi(strA.c_str()) * 10000));
32188 }
32189
32190 // Calculates log2 of number.
32191 double FFScript::Log2( double n )
32192 {
32193 // log(n)/log(2) is log2.
32194 return log( (double)n ) / log( (double)2 );
32195 }
32196
32197 //xtoa, convert hex number to hex ascii
32198 14 void FFScript::do_xtoa()
32199 {
32200
32201 14 int32_t arrayptr_a = get_register(sarg1);
32202 14 int32_t number = get_register(sarg2) / 10000;//ri->d[rEXP2]/10000; //why are you not in sarg2?!!
32203
32204
32205
32206 14 bool isneg = false;
32207
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if ( number < 0 )
32208 {
32209 isneg = true;
32210 number *= -1;
32211 }
32212 14 double num = number;
32213
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 int32_t digits = num ? floor(FFCore.LogToBase(num, 16) + 1) : 1;
32214
32215
32216 14 int32_t pos = 0;
32217 14 string strA;
32218
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(number == 0) //Needs to precede str.resize(digits+3) as if the number is <= 0 then this breaks.
32219 {
32220 strA.resize(3);
32221 strA[pos+2] = '0';
32222 if(ArrayH::setArray(arrayptr_a, strA) == SH::_Overflow)
32223 {
32224 Z_scripterrlog("Dest string supplied to 'itoa()' not large enough\n");
32225 set_register(sarg1, 0);
32226 }
32227 else set_register(sarg1, 30000); //returns the pointer to the dest
32228 return;
32229 }
32230 14 int32_t ret = 0;
32231
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 strA.resize(digits+3+(isneg?1:0));
32232 //num = Floor(Abs(num));
32233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if ( isneg )
32234 {
32235 strA[pos] = '-';
32236 strA[pos+1] = '0';
32237 strA[pos+2] = 'x';
32238 ret = 3;
32239 }
32240 else
32241 {
32242
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 strA[pos] = '0';
32243
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 strA[pos+1] = 'x';
32244 14 ret = 2;
32245 }
32246
32247 14 int32_t alphaoffset = 'A' - 0xA;
32248
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 24 times.
38 for(int32_t i = 0; i < digits; ++i)
32249 {
32250
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 int32_t coeff = ((int32_t)floor((double)(((double)number) / pow((float)0x10, digits - i - 1))) % 0x10);
32251
3/4
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 strA[pos + ret + i] = coeff < 0xA ? coeff + '0' : coeff + alphaoffset;
32252 24 }
32253
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
14 if(ArrayH::setArray(arrayptr_a, strA) == SH::_Overflow)
32254 {
32255 Z_scripterrlog("Dest string supplied to 'xtoa()' not large enough\n");
32256 set_register(sarg1, 0);
32257 }
32258
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 else set_register(sarg1, (ret + digits -(isneg?1:0))*10000); //don't count the - sign as a digit
32259
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 }
32260
32261 void FFScript::do_ilen(const bool v)
32262 {
32263 int32_t arrayptr = (SH::get_arg(sarg2, v));
32264 string str;
32265 ArrayH::getString(arrayptr, str);
32266 set_register(sarg1, (FFCore.ilen((char*)str.c_str()) * 10000));
32267 }
32268
32269 //! Note atoi2 (atoi(str, len) can be accompished with str.resize after getString.
32270 void FFScript::do_atoi(const bool v)
32271 {
32272 int32_t arrayptr = (SH::get_arg(sarg2, v));
32273 string str;
32274 ArrayH::getString(arrayptr, str);
32275 set_register(sarg1, (atoi(str.c_str()) * 10000));
32276 }
32277 void FFScript::do_atol(const bool v)
32278 {
32279 int32_t arrayptr = (SH::get_arg(sarg2, v));
32280 string str;
32281 ArrayH::getString(arrayptr, str);
32282 set_register(sarg1, (atoi(str.c_str())));
32283 }
32284
32285 void FFScript::do_strstr()
32286 {
32287
32288 int32_t arrayptr_a = ri->d[rINDEX];
32289 int32_t arrayptr_b = ri->d[rINDEX2];
32290 string strA;
32291 string strB;
32292 ArrayH::getString(arrayptr_a, strA);
32293 ArrayH::getString(arrayptr_b, strB);
32294 if ( strA.size() < 1 )
32295 {
32296 Z_scripterrlog("String passed to strstr() is too small. Size is: %d \n", strA.size());
32297 set_register(sarg1,-10000);
32298 return;
32299 }
32300 set_register(sarg1, (strA.find(strB) * 10000));
32301 }
32302
32303 935 void FFScript::do_strcat()
32304 {
32305
32306 935 int32_t arrayptr_a = ri->d[rINDEX];
32307 935 int32_t arrayptr_b = ri->d[rINDEX2];
32308 935 string strA;
32309 935 string strB;
32310
1/2
✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
935 ArrayH::getString(arrayptr_a, strA);
32311
1/2
✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
935 ArrayH::getString(arrayptr_b, strB);
32312 //char str_c[2048];
32313 //strcpy(str_c, strA.c_str());
32314
1/2
✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
935 string strC = strA + strB;
32315
2/4
✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 935 times.
935 if(ArrayH::setArray(arrayptr_a, strC) == SH::_Overflow)
32316 {
32317 Z_scripterrlog("Dest string supplied to 'strcat()' not large enough\n");
32318 set_register(sarg1, 0);
32319 }
32320
1/2
✓ Branch 0 taken 935 times.
✗ Branch 1 not taken.
935 else set_register(sarg1, arrayptr_a); //returns the pointer to the dest
32321 935 }
32322 void FFScript::do_strspn()
32323 {
32324
32325 int32_t arrayptr_a = ri->d[rINDEX];
32326 int32_t arrayptr_b = ri->d[rINDEX2];
32327 string strA;
32328 string strB;
32329 ArrayH::getString(arrayptr_a, strA);
32330 ArrayH::getString(arrayptr_b, strB);
32331 set_register(sarg1, (strspn(strA.c_str(), strB.c_str()) * 10000));
32332 }
32333
32334 void FFScript::do_strcspn()
32335 {
32336
32337 int32_t arrayptr_a = ri->d[rINDEX];
32338 int32_t arrayptr_b = ri->d[rINDEX2];
32339 string strA;
32340 string strB;
32341 ArrayH::getString(arrayptr_a, strA);
32342 ArrayH::getString(arrayptr_b, strB);
32343 set_register(sarg1, (strcspn(strA.c_str(), strB.c_str()) * 10000));
32344 }
32345
32346 void FFScript::do_strchr()
32347 {
32348
32349 int32_t arrayptr_a = ri->d[rINDEX];
32350 char chr_to_find = (ri->d[rINDEX2]/10000);
32351 string strA;
32352 ArrayH::getString(arrayptr_a, strA);
32353 if ( strA.size() < 1 )
32354 {
32355 Z_scripterrlog("String passed to strchr() is too small. Size is: %d \n", strA.size());
32356 set_register(sarg1,-10000);
32357 return;
32358 }
32359
32360 set_register(sarg1,strA.find_first_of(chr_to_find)*10000);
32361 }
32362 void FFScript::do_strrchr()
32363 {
32364 int32_t arrayptr_a = ri->d[rINDEX];
32365 char chr_to_find = (ri->d[rINDEX2]/10000);
32366 string strA;
32367 ArrayH::getString(arrayptr_a, strA);
32368 if ( strA.size() < 1 )
32369 {
32370 Z_scripterrlog("String passed to strrchr() is too small. Size is: %d \n", strA.size());
32371 set_register(sarg1,-10000);
32372 return;
32373 }
32374 set_register(sarg1,strA.find_last_of(chr_to_find)*10000);
32375 }
32376
32377 void FFScript::do_remchr2()
32378 {
32379 //Not implemented, remchr not found
32380 //not part of any standard library
32381 int32_t arrayptr_a = ri->d[rINDEX];
32382 string strA;
32383 ArrayH::getString(arrayptr_a, strA);
32384 }
32385 //Bookmark
32386 void FFScript::do_atoi2()
32387 {
32388 //not implemented; atoi does not take 2 params
32389 int32_t arrayptr_a = ri->d[rINDEX];
32390 string strA;
32391 ArrayH::getString(arrayptr_a, strA);
32392 }
32393 void FFScript::do_ilen2()
32394 {
32395 //not implemented, ilen not found
32396 int32_t arrayptr_a = ri->d[rINDEX];
32397 string strA;
32398 ArrayH::getString(arrayptr_a, strA);
32399 }
32400 void FFScript::do_xlen2()
32401 {
32402 //not implemented, xlen not found
32403 int32_t arrayptr_a = ri->d[rINDEX];
32404 string strA;
32405 ArrayH::getString(arrayptr_a, strA);
32406 }
32407
32408 4797 void FFScript::do_itoa()
32409 {
32410 4797 int32_t arrayptr_a = get_register(sarg1);
32411 4797 int32_t number = get_register(sarg2) / 10000;
32412
32413 char buf[16];
32414 4797 zc_itoa(number, buf, 10);
32415 4797 int32_t ret = ::strlen(buf) * 10000L;
32416
1/2
✓ Branch 0 taken 4797 times.
✗ Branch 1 not taken.
4797 string strA(buf);
32417
32418
2/4
✓ Branch 0 taken 4797 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4797 times.
4797 if(ArrayH::setArray(arrayptr_a, strA) == SH::_Overflow)
32419 {
32420 Z_scripterrlog("Dest string supplied to 'itoa()' not large enough\n");
32421 set_register(sarg1, -1);
32422 }
32423
1/2
✓ Branch 0 taken 4797 times.
✗ Branch 1 not taken.
4797 else set_register(sarg1, ret); //returns the number of digits used
32424 4797 }
32425
32426 56 void FFScript::do_itoacat()
32427 {
32428 56 int32_t arrayptr_a = get_register(sarg1);
32429 56 int32_t number = get_register(sarg2) / 10000;
32430
32431 56 double num = number;
32432 56 int32_t digits = FFCore.numDigits(number); //int32_t(log10(temp) * 10000.0)
32433 56 int32_t pos = 0;
32434 56 int32_t ret = 0;
32435 56 string strA;
32436 56 string strB;
32437
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 strB.resize(digits);
32438
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 ArrayH::getString(arrayptr_a, strA);
32439
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 if(num < 0)
32440 {
32441 strB.resize(digits+1);
32442 strB[pos] = '-';
32443 ++ret;
32444 num = -num;
32445 }
32446
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 else if(num == 0)
32447 {
32448 strB[pos] = '0';
32449 string strC = strA + strB;
32450 if(ArrayH::setArray(arrayptr_a, strC) == SH::_Overflow)
32451 {
32452 Z_scripterrlog("Dest string supplied to 'itoacat()' not large enough\n");
32453 set_register(sarg1, 0);
32454 }
32455 else set_register(sarg1, arrayptr_a); //returns the pointer to the dest
32456 return;
32457 }
32458
32459
32460
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 84 times.
140 for(int32_t i = 0; i < digits; ++i)
32461
2/4
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
84 strB[pos + ret + i] = ((int32_t)floor((double)(num / pow((float)10, digits - i - 1))) % 10) + '0';
32462
32463
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 string strC = strA + strB;
32464
2/4
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 56 times.
56 if(ArrayH::setArray(arrayptr_a, strC) == SH::_Overflow)
32465 {
32466 Z_scripterrlog("Dest string supplied to 'itoacat()' not large enough\n");
32467 set_register(sarg1, 0);
32468 }
32469
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 else set_register(sarg1, arrayptr_a); //returns the pointer to the dest
32470
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 }
32471
32472 2925 void FFScript::do_strcpy(const bool a, const bool b)
32473 {
32474 2925 int32_t arrayptr_b = SH::get_arg(sarg1, a);
32475 2925 int32_t arrayptr_a = SH::get_arg(sarg2, b);
32476
32477 2925 string strA;
32478
32479
1/2
✓ Branch 0 taken 2925 times.
✗ Branch 1 not taken.
2925 ArrayH::getString(arrayptr_a, strA);
32480
32481
2/4
✓ Branch 0 taken 2925 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2925 times.
2925 if(ArrayH::setArray(arrayptr_b, strA) == SH::_Overflow)
32482 Z_scripterrlog("Dest string supplied to 'strcpy()' not large enough\n");
32483 2925 }
32484 2 void FFScript::do_arraycpy(const bool a, const bool b)
32485 {
32486 2 int32_t arrayptr_dest = SH::get_arg(sarg1, a);
32487 2 int32_t arrayptr_src = SH::get_arg(sarg2, b);
32488 2 ArrayH::copyValues(arrayptr_dest, arrayptr_src);
32489 2 }
32490 6050 void FFScript::do_strlen(const bool v)
32491 {
32492 6050 int32_t arrayptr = (SH::get_arg(sarg2, v));
32493 6050 string str;
32494
1/2
✓ Branch 0 taken 6050 times.
✗ Branch 1 not taken.
6050 ArrayH::getString(arrayptr, str);
32495
1/2
✓ Branch 0 taken 6050 times.
✗ Branch 1 not taken.
6050 set_register(sarg1, (str.length() * 10000));
32496 6050 }
32497
32498 void FFScript::do_strncmp()
32499 {
32500 int32_t arrayptr_a = ri->d[rINDEX];
32501 int32_t arrayptr_b = ri->d[rEXP2];
32502 int32_t len = ri->d[rEXP1]/10000;
32503 string strA;
32504 string strB;
32505 ArrayH::getString(arrayptr_a, strA);
32506 ArrayH::getString(arrayptr_b, strB);
32507 set_register(sarg1, (strncmp(strA.c_str(), strB.c_str(), len) * 10000));
32508 }
32509
32510 void FFScript::do_strnicmp()
32511 {
32512 int32_t arrayptr_a = ri->d[rINDEX];
32513 int32_t arrayptr_b = ri->d[rEXP2];
32514 int32_t len = ri->d[rEXP1]/10000;
32515 string strA;
32516 string strB;
32517 ArrayH::getString(arrayptr_a, strA);
32518 ArrayH::getString(arrayptr_b, strB);
32519 set_register(sarg1, (ustrnicmp(strA.c_str(), strB.c_str(), len) * 10000));
32520 }
32521
32522 /////////////////////
32523 /// MATHS HELPERS ///
32524 /////////////////////
32525
32526 //Returns the log of val to the base 10. Any value <= 0 will return 0.
32527 int32_t FFScript::Log10(double temp)
32528 {
32529 int32_t ret = 0;
32530 if(temp > 0)
32531 ret = int32_t(log10(temp) * 10000.0);
32532 else ret = 0;
32533 return ret;
32534 }
32535
32536 //Returns the number of digits in a given integer.
32537 56 int32_t FFScript::numDigits(int32_t number)
32538 {
32539 56 int32_t digits = 0;
32540
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 56 times.
140 while (number)
32541 {
32542 84 number /= 10;
32543 84 digits++;
32544 }
32545 56 return digits;
32546 }
32547
32548 // Returns the natural logarithm of val (to the base e). Any value <= 0 will return 0.
32549 28 double FFScript::ln(double temp)
32550 {
32551
32552
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 if(temp > 0)
32553 28 return (log(temp));
32554 else
32555 {
32556 return 0;
32557 }
32558 28 }
32559
32560 // Returns the logarithm of x to the given base.
32561 14 double FFScript::LogToBase(double x, double base)
32562 {
32563
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
14 if(x <= 0 || base <= 0) return 0;
32564 14 return FFCore.ln(x)/FFCore.ln(base);
32565 14 }
32566
32567 ///----------------------------------------------------------------------------------------------------//
32568 //Debugger and Logging Consoles
32569
32570 template <typename ...Params>
32571 void FFScript::ZScriptConsole(int32_t attributes,const char *format, Params&&... params)
32572 {
32573 //if ( open )
32574 {
32575 zscript_coloured_console.Create("ZQuest Classic Logging Console", 600, 200, NULL, NULL);
32576 zscript_coloured_console.cls(CConsoleLoggerEx::COLOR_BACKGROUND_BLACK);
32577 zscript_coloured_console.gotoxy(0,0);
32578 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
32579 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"ZQuest Classic Logging Console\n");
32580
32581 zscript_coloured_console.cprintf( attributes, format, std::forward<Params>(params)...);
32582 }
32583 //else
32584 //{
32585 //close
32586 // zscript_coloured_console.Close();
32587 //}
32588 }
32589
32590 420 void clearConsole()
32591 {
32592 420 zscript_coloured_console.cls(CConsoleLoggerEx::COLOR_BACKGROUND_BLACK);
32593 420 zscript_coloured_console.gotoxy(0,0);
32594
32595 420 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_RED | CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
32596 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"\n _____ ____ __ \n");
32597 420 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_RED | CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
32598 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK," /__ / / __ \\__ _____ _____/ /_\n");
32599 420 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_RED | CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
32600 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK," / / / / / / / / / _ \\/ ___/ __/\n");
32601 420 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_RED | CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
32602 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK," / /__/ /_/ / /_/ / __(__ ) /_ \n");
32603 420 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_RED | CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
32604 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK," /____/\\___\\_\\__,_/\\___/____/\\__/\n\n");
32605
32606 420 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
32607 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"ZC Console\n");
32608
32609 840 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE |CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
32610 420 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"Running: %s\n", getVersionString());
32611
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 418 times.
420 if ( FFCore.getQuestHeaderInfo(vZelda) > 0 )
32612 {
32613 418 char const* verstr = QHeader.getVerStr();
32614
2/2
✓ Branch 0 taken 309 times.
✓ Branch 1 taken 109 times.
418 if(verstr[0])
32615 {
32616 109 auto vercmp = QHeader.compareVer();
32617 109 auto astatecmp = compare(int32_t(QHeader.getAlphaState()), getAlphaState());
32618 109 auto avercmp = compare(QHeader.getAlphaVer(), 0);
32619 109 auto timecmp = QHeader.compareDate();
32620
4/6
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 91 times.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18 times.
109 if(!(vercmp || astatecmp || avercmp))
32621 {
32622
3/4
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
18 if(!timecmp || !QHeader.new_version_is_nightly)
32623 36 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE |CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
32624 18 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"Quest Made in this build\n", verstr);
32625 else if(timecmp < 0)
32626 {
32627 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE |CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
32628 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"Quest Made in an earlier nightly of the same build\n", verstr);
32629 }
32630 else
32631 {
32632 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE |CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
32633 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"Quest Made in an LATER nightly of the same build!\n"
32634 "This may be unsafe to play in this version!\n", verstr);
32635 }
32636 18 }
32637 182 else zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE |CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
32638 91 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"Quest Made in: %s\n", verstr);
32639 109 }
32640 418 }
32641 420 }
32642 void FFScript::ZScriptConsole(bool open)
32643 {
32644 if ( open )
32645 {
32646 zscript_coloured_console.Create("ZC Console", 600, 200, NULL, NULL);
32647 clearConsole();
32648 console_enabled = 1;
32649 }
32650 else
32651 {
32652 zscript_coloured_console.Close();
32653 console_enabled = 0;
32654 }
32655 zc_set_config("CONSOLE","enabled",console_enabled);
32656 }
32657
32658 ///----------------------------------------------------------------------------------------------------//
32659 //Tracing
32660
32661 10317 void FFScript::do_trace(bool v)
32662 {
32663
5/14
✗ Branch 0 not taken.
✓ Branch 1 taken 10317 times.
✓ Branch 2 taken 10317 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10317 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 10317 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 10317 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
20634 bool should_replay_trace = replay_is_active() && replay_get_meta_bool("script_trace");
32664 // For now, only prevent tracing to allegro log for Web version. Some quests may expect players to
32665 // look in the logs for spoiler/secret stuff.
32666 #ifdef __EMSCRIPTEN__
32667 bool should_trace = console_enabled || should_replay_trace;
32668 if (!should_trace) return;
32669 #endif
32670
32671 10317 int32_t temp = SH::get_arg(sarg1, v);
32672
32673 char tmp[100];
32674
2/2
✓ Branch 0 taken 10311 times.
✓ Branch 1 taken 6 times.
10317 sprintf(tmp, (temp < 0 ? "%06d" : "%05d"), temp);
32675
1/2
✓ Branch 0 taken 10317 times.
✗ Branch 1 not taken.
10317 string s2(tmp);
32676
5/10
✓ Branch 0 taken 10317 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10317 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10317 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10317 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 10317 times.
✗ Branch 9 not taken.
10317 s2 = s2.substr(0, s2.size() - 4) + "." + s2.substr(s2.size() - 4, 4) + "\n";
32677
1/2
✓ Branch 0 taken 10317 times.
✗ Branch 1 not taken.
10317 TraceScriptIDs();
32678
1/2
✓ Branch 0 taken 10317 times.
✗ Branch 1 not taken.
10317 al_trace("%s", s2.c_str());
32679
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 10277 times.
10317 if (should_replay_trace)
32680
2/4
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
40 replay_step_comment("trace: " + s2);
32681
32682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10317 times.
10317 if ( console_enabled )
32683 {
32684 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
32685 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),s2.c_str());
32686 }
32687 10317 }
32688 void FFScript::do_tracel(bool v)
32689 {
32690 int32_t temp = SH::get_arg(sarg1, v);
32691
32692 char tmp[32];
32693 sprintf(tmp, "%d\n", temp);
32694 TraceScriptIDs();
32695 al_trace("%s", tmp);
32696 if (replay_is_active() && replay_get_meta_bool("script_trace"))
32697 replay_step_comment(fmt::format("trace: {}", temp));
32698
32699 if ( console_enabled )
32700 {
32701 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
32702 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),tmp);
32703 }
32704 }
32705
32706 void FFScript::do_tracebool(const bool v)
32707 {
32708 int32_t temp = SH::get_arg(sarg1, v);
32709 TraceScriptIDs();
32710 char const* str = temp ? "true\n" : "false\n";
32711 al_trace("%s", str);
32712 if (replay_is_active() && replay_get_meta_bool("script_trace"))
32713 replay_step_comment(fmt::format("trace: {}", (bool)temp));
32714
32715 if ( console_enabled )
32716 {
32717 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
32718 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),str);
32719 }
32720 }
32721
32722 35222 void traceStr(string const& str)
32723 {
32724 35222 FFCore.TraceScriptIDs();
32725 35222 safe_al_trace(str);
32726
7/16
✗ Branch 0 not taken.
✓ Branch 1 taken 35222 times.
✓ Branch 2 taken 35222 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 35222 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 35222 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 35222 times.
✓ Branch 10 taken 1642 times.
✓ Branch 11 taken 33580 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
70444 if (replay_is_active() && replay_get_meta_bool("script_trace"))
32727
1/2
✓ Branch 0 taken 33580 times.
✗ Branch 1 not taken.
33580 replay_step_comment("trace: " + str);
32728
32729
1/2
✓ Branch 0 taken 35222 times.
✗ Branch 1 not taken.
35222 if ( console_enabled )
32730 {
32731 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
32732 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),str.c_str());
32733 }
32734 35222 }
32735
32736 1373 void FFScript::do_tracestring()
32737 {
32738 1373 int32_t arrayptr = get_register(sarg1);
32739 1373 string str;
32740
1/2
✓ Branch 0 taken 1373 times.
✗ Branch 1 not taken.
1373 ArrayH::getString(arrayptr, str, 512);
32741
1/2
✓ Branch 0 taken 1373 times.
✗ Branch 1 not taken.
1373 str += "\0"; //In the event that the user passed an array w/o NULL, don't crash.
32742
1/2
✓ Branch 0 taken 1373 times.
✗ Branch 1 not taken.
1373 traceStr(str);
32743 1373 }
32744
32745 bool is_valid_format(char c)
32746 {
32747 switch(c)
32748 {
32749 case 'f': case 'd': case 'i': case 'p':
32750 case 'l': case 's': case 'c': case 'X':
32751 case 'x': case 'b': case 'B': case 'a':
32752 return true;
32753 }
32754 return false;
32755 }
32756 #define FORMATTER_FLAG_0FILL 0x01
32757 88429 char const* zs_formatter(char const* format, int32_t arg, int32_t mindig, dword flags)
32758 {
32759
3/4
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 88382 times.
✓ Branch 2 taken 47 times.
✗ Branch 3 not taken.
88429 static std::string ret;
32760
32761 88429 ret.clear();
32762
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 88429 times.
88429 if(format)
32763 {
32764 176858 std::string mdstr = fmt::format("%{}{}{}",(flags&FORMATTER_FLAG_0FILL)?"0":"",
32765
2/4
✓ Branch 0 taken 88429 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 88429 times.
88429 mindig, (format[0] == 'x' || format[0] == 'X') ? format[0] : 'd');
32766 88429 char const* mindigbuf = mdstr.c_str();
32767 88429 bool tempbool = false;
32768
3/12
✓ Branch 0 taken 552 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 79510 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 8367 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
88429 switch(format[0])
32769 {
32770 case 'f':
32771 tempbool = true;
32772 [[fallthrough]];
32773 case 'd':
32774
2/2
✓ Branch 0 taken 78567 times.
✓ Branch 1 taken 943 times.
80453 if(arg%10000)
32775 943 tempbool = true;
32776 [[fallthrough]];
32777 case 'i':
32778 case 'p':
32779 {
32780 79510 char argbuf[32] = {0};
32781 79510 bool neg = arg < 0;
32782
2/2
✓ Branch 0 taken 78093 times.
✓ Branch 1 taken 1417 times.
79510 if(mindig)
32783 1417 sprintf(argbuf,mindigbuf,arg / 10000);
32784
1/2
✓ Branch 0 taken 78093 times.
✗ Branch 1 not taken.
78093 else zc_itoa(arg / 10000, argbuf);
32785
32786
2/2
✓ Branch 0 taken 78567 times.
✓ Branch 1 taken 943 times.
79510 if(tempbool) //add decimal places
32787 {
32788 943 arg = abs(arg);
32789 943 auto ind = strlen(argbuf);
32790 943 argbuf[ind++] = '.';
32791
2/2
✓ Branch 0 taken 3772 times.
✓ Branch 1 taken 943 times.
4715 for(int div = 1000; div > 0; div /= 10)
32792 3772 argbuf[ind++] = '0' + (arg/div)%10;
32793
4/4
✓ Branch 0 taken 943 times.
✓ Branch 1 taken 488 times.
✓ Branch 2 taken 488 times.
✓ Branch 3 taken 943 times.
1431 for(--ind; argbuf[ind]=='0' && argbuf[ind-1]!='-'; --ind)
32794 {
32795 488 argbuf[ind] = 0;
32796 488 }
32797 943 }
32798
32799
4/4
✓ Branch 0 taken 10938 times.
✓ Branch 1 taken 68572 times.
✓ Branch 2 taken 104 times.
✓ Branch 3 taken 10834 times.
79510 if(neg && argbuf[0] != '-')
32800
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 ret = "-";
32801
1/2
✓ Branch 0 taken 79510 times.
✗ Branch 1 not taken.
79510 ret += argbuf;
32802 79510 return ret.c_str();
32803 }
32804 //
32805 case 'l':
32806 {
32807 char argbuf[32] = {0};
32808 if(mindig)
32809 sprintf(argbuf, mindigbuf, arg);
32810 else zc_itoa(arg, argbuf);
32811
32812 ret = argbuf;
32813 return ret.c_str();
32814 }
32815 //
32816 case 's':
32817 {
32818
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8367 times.
8367 if(mindig)
32819 Z_scripterrlog("Cannot use minimum digits flag for '%%s'\n");
32820
1/2
✓ Branch 0 taken 8367 times.
✗ Branch 1 not taken.
8367 if(arg)
32821 {
32822 8367 int32_t strptr = arg;
32823
1/2
✓ Branch 0 taken 8367 times.
✗ Branch 1 not taken.
8367 ArrayManager am(strptr);
32824
2/4
✓ Branch 0 taken 8367 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8367 times.
8367 if(am.invalid())
32825 ret = "<INVALID STRING>";
32826
1/2
✓ Branch 0 taken 8367 times.
✗ Branch 1 not taken.
8367 else ArrayH::getString(strptr, ret, MAX_ZC_ARRAY_SIZE);
32827 8367 }
32828 else ret = "<NULL>";
32829 8367 return ret.c_str();
32830 }
32831 case 'c':
32832 {
32833
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 552 times.
552 if(mindig)
32834 Z_scripterrlog("Cannot use minimum digits flag for '%%c'\n");
32835 552 int32_t c = (arg / 10000);
32836
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 552 times.
552 if ( (byte(c)) != c )
32837 {
32838 Z_scripterrlog("Illegal char value (%d) passed to sprintf as '%%c' arg\n", c);
32839 Z_scripterrlog("Value of invalid char will overflow.\n");
32840 }
32841
1/2
✓ Branch 0 taken 552 times.
✗ Branch 1 not taken.
552 ret.push_back(byte(c));
32842 552 return ret.c_str();
32843 }
32844 //
32845 case 'X':
32846 tempbool = true;
32847 [[fallthrough]];
32848 case 'x':
32849 {
32850 char argbuf[32] = {0};
32851 if(mindig)
32852 sprintf(argbuf,mindigbuf,arg / 10000);
32853 else zc_itoa( (arg/10000), argbuf, 16 ); //base 16; hex
32854
32855 for ( int32_t inx = 0; inx < 16; ++inx ) //set chosen caps
32856 {
32857 argbuf[inx] = ( tempbool ? toupper(argbuf[inx]) : tolower(argbuf[inx]) );
32858 }
32859 ret = "0x";
32860 ret += argbuf;
32861 return ret.c_str();
32862 }
32863 //
32864 case 'b': //int binary
32865 arg /= 10000;
32866 [[fallthrough]];
32867 case 'B': //long binary
32868 {
32869 char argbuf[33] = {0};
32870 int num_digits = mindig;
32871 for(int q = num_digits; q < 32; ++q)
32872 if(arg&(1<<q))
32873 num_digits = q+1;
32874 for(int q = 0; q < num_digits; ++q)
32875 {
32876 argbuf[q] = (arg&(1<<(num_digits-q-1)))
32877 ? '1' : '0';
32878 }
32879 ret = argbuf;
32880 return ret.c_str();
32881 }
32882 case 'a': //array
32883 {
32884 if(arg)
32885 {
32886 if(!is_valid_format(format[1]))
32887 {
32888 Z_scripterrlog("Format '%%a%c' is invalid!\n",format[1]);
32889 break;
32890 }
32891 ArrayManager am(arg);
32892 ret = am.asString([&](int32_t val)
32893 {
32894 return zs_formatter(format+1, val, mindig, flags);
32895 }, 214748);
32896 }
32897 else ret = "{ NULL }";
32898 return ret.c_str();
32899 }
32900 default:
32901 {
32902 Z_scripterrlog("Error: '%%%c' is not a valid printf argument.\n",format[0]);
32903 return ret.c_str();
32904 }
32905 }
32906
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 88429 times.
✗ Branch 2 not taken.
88429 }
32907 Z_scripterrlog("Error: No format parameter given for zs_formatter\n");
32908 return ret.c_str();
32909 88429 }
32910
32911 64881 static int32_t zspr_varg_getter(int32_t,int32_t next_arg)
32912 {
32913 64881 return zs_vargs.at(next_arg);
32914 }
32915 23548 static int32_t zspr_stack_getter(int32_t num_args, int32_t next_arg)
32916 {
32917 23548 return SH::read_stack(((ri->sp + num_args) - 1) - next_arg);
32918 }
32919 45813 string zs_sprintf(char const* format, int32_t num_args, std::function<int32_t(int32_t,int32_t)> arg_getter)
32920 {
32921 45813 int32_t next_arg = 0;
32922 45813 bool is_old_args = get_qr(qr_OLD_PRINTF_ARGS);
32923 45813 ostringstream oss;
32924
2/2
✓ Branch 0 taken 12079 times.
✓ Branch 1 taken 122163 times.
134242 while(format[0] != '\0')
32925 {
32926 122163 int32_t arg_val = 0;
32927
2/2
✓ Branch 0 taken 88429 times.
✓ Branch 1 taken 33734 times.
122163 if(next_arg < num_args)
32928 {
32929
1/2
✓ Branch 0 taken 88429 times.
✗ Branch 1 not taken.
88429 arg_val = arg_getter(num_args,next_arg);
32930 88429 }
32931
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33734 times.
33734 else if(get_qr(qr_PRINTF_NO_0FILL))
32932 {
32933 oss << format;
32934 return oss.str();
32935 }
32936 122163 char buf[256] = {0};
32937
2/2
✓ Branch 0 taken 88429 times.
✓ Branch 1 taken 460709 times.
549138 for ( int32_t q = 0; q < 256; ++q )
32938 {
32939
2/2
✓ Branch 0 taken 33734 times.
✓ Branch 1 taken 426975 times.
460709 if(format[0] == '\0') //done
32940 {
32941
1/2
✓ Branch 0 taken 33734 times.
✗ Branch 1 not taken.
33734 oss << buf;
32942
1/2
✓ Branch 0 taken 33734 times.
✗ Branch 1 not taken.
33734 return oss.str();
32943 }
32944
2/2
✓ Branch 0 taken 89059 times.
✓ Branch 1 taken 337916 times.
426975 else if(format[0] == '%')
32945 {
32946 89059 ++format;
32947 89059 int32_t min_digits = 0;
32948 89059 dword formatter_flags = 0;
32949
5/6
✓ Branch 0 taken 88429 times.
✓ Branch 1 taken 630 times.
✓ Branch 2 taken 1417 times.
✓ Branch 3 taken 87012 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1417 times.
89059 if(format[0] >= '0' && format[0] <= '9' && !is_old_args)
32950 {
32951 1417 char argbuf[4] = {0};
32952 1417 int32_t q = 0;
32953
1/2
✓ Branch 0 taken 1417 times.
✗ Branch 1 not taken.
1417 if(format[0] == '0') //Leading 0 means to 0-fill, and gets eaten
32954 1417 formatter_flags |= FORMATTER_FLAG_0FILL;
32955 else --format; //else don't eat
32956
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2834 times.
2834 while(q < 4)
32957 {
32958 2834 ++format;
32959 2834 char c = format[0];
32960
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2834 times.
2834 if(c == '\0')
32961 {
32962 Z_scripterrlog("Cannot use minimum digits flag with no argument\n");
32963 oss << buf;
32964 return oss.str();
32965 }
32966
3/4
✓ Branch 0 taken 2834 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1417 times.
✓ Branch 3 taken 1417 times.
2834 if(c >= '0' && c <= '9')
32967 1417 argbuf[q++] = c;
32968 else
32969 {
32970 1417 --format;
32971 1417 break;
32972 }
32973 }
32974 1417 ++format;
32975 1417 min_digits = atoi(argbuf);
32976
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1417 times.
1417 if(!min_digits)
32977 {
32978 Z_scripterrlog("Error formatting string: Invalid number '%s'\n", argbuf);
32979 }
32980 1417 }
32981
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 89059 times.
89059 bool bin = (format[0] == 'b' || format[0] == 'B');
32982
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 89059 times.
89059 bool hex = (format[0] == 'x' || format[0] == 'X');
32983
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 89059 times.
89059 if(bin)
32984 {
32985 if(min_digits > 32)
32986 {
32987 Z_scripterrlog("Min digits argument cannot be larger than 32!"
32988 " Value will be truncated to 32.");
32989 min_digits = 32;
32990 }
32991 }
32992
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 89059 times.
89059 else if(min_digits > 10)
32993 {
32994 Z_scripterrlog("Min digits argument cannot be larger than 10!"
32995 " Value will be truncated to 10.");
32996 min_digits = 10;
32997 }
32998
32999 89059 bool tempbool = false;
33000
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 88429 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 630 times.
89059 switch( format[0] )
33001 {
33002 case 'd':
33003 case 'f':
33004 case 'i': case 'p':
33005 case 'l':
33006 case 's':
33007 case 'c':
33008 case 'x': case 'X':
33009 case 'b': case 'B':
33010 {
33011 88429 ++next_arg;
33012
3/6
✓ Branch 0 taken 88429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 88429 times.
✗ Branch 5 not taken.
88429 oss << buf << zs_formatter(format,arg_val,min_digits,formatter_flags);
33013 88429 q = 300; //break main loop
33014 88429 break;
33015 }
33016 case 'a': //array print
33017 {
33018 ++next_arg;
33019 oss << buf << zs_formatter(format,arg_val,min_digits,formatter_flags);
33020 while(format[0] == 'a')
33021 {
33022 if(is_valid_format(format[1]))
33023 ++format;
33024 else break;
33025 }
33026 q = 300; //break main loop
33027 break;
33028 }
33029 case '%':
33030 {
33031
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 630 times.
630 if(min_digits)
33032 Z_scripterrlog("Cannot use minimum digits flag for '%%%%'\n");
33033 630 buf[q] = '%';
33034 630 break;
33035 }
33036 default:
33037 {
33038 if(is_old_args)
33039 buf[q] = format[0];
33040 else
33041 {
33042 Z_scripterrlog("Error: '%%%c' is not a valid printf argument.\n",format[0]);
33043 }
33044 break;
33045 }
33046 }
33047 89059 ++format;
33048 89059 }
33049 else
33050 {
33051 337916 buf[q] = format[0];
33052 337916 ++format;
33053 }
33054
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 426975 times.
426975 if(q == 255)
33055 {
33056 oss << buf;
33057 break;
33058 }
33059 426975 }
33060 }
33061
1/2
✓ Branch 0 taken 12079 times.
✗ Branch 1 not taken.
12079 return oss.str();
33062 45813 }
33063
33064 33849 void FFScript::do_printf(const bool v, const bool varg)
33065 {
33066 int32_t num_args, format_arrayptr;
33067
2/2
✓ Branch 0 taken 33562 times.
✓ Branch 1 taken 287 times.
33849 if(varg)
33068 {
33069 33562 num_args = zs_vargs.size();
33070 33562 format_arrayptr = SH::read_stack(ri->sp);
33071 33562 }
33072 else
33073 {
33074 287 num_args = SH::get_arg(sarg1, v) / 10000;
33075 287 format_arrayptr = SH::read_stack(ri->sp + num_args);
33076 }
33077 33849 ArrayManager fmt_am(format_arrayptr);
33078
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33849 times.
33849 if(!fmt_am.invalid())
33079 {
33080 33849 string formatstr;
33081
1/2
✓ Branch 0 taken 33849 times.
✗ Branch 1 not taken.
33849 ArrayH::getString(format_arrayptr, formatstr, MAX_ZC_ARRAY_SIZE);
33082
33083
4/6
✓ Branch 0 taken 33562 times.
✓ Branch 1 taken 287 times.
✓ Branch 2 taken 33849 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 33849 times.
33849 traceStr(zs_sprintf(formatstr.c_str(), num_args, varg ? zspr_varg_getter : zspr_stack_getter));
33084 33849 }
33085
2/2
✓ Branch 0 taken 287 times.
✓ Branch 1 taken 33562 times.
33849 if(varg)
33086 33562 zs_vargs.clear();
33087 33849 }
33088 11964 void FFScript::do_sprintf(const bool v, const bool varg)
33089 {
33090 int32_t num_args, dest_arrayptr, format_arrayptr;
33091
2/2
✓ Branch 0 taken 319 times.
✓ Branch 1 taken 11645 times.
11964 if(varg)
33092 {
33093 319 num_args = zs_vargs.size();
33094 319 dest_arrayptr = SH::read_stack(ri->sp + 1);
33095 319 format_arrayptr = SH::read_stack(ri->sp);
33096 319 }
33097 else
33098 {
33099 11645 num_args = SH::get_arg(sarg1, v) / 10000;
33100 11645 dest_arrayptr = SH::read_stack(ri->sp + num_args + 1);
33101 11645 format_arrayptr = SH::read_stack(ri->sp + num_args);
33102 }
33103 11964 ArrayManager fmt_am(format_arrayptr);
33104 11964 ArrayManager dst_am(dest_arrayptr);
33105
2/4
✓ Branch 0 taken 11964 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11964 times.
11964 if(fmt_am.invalid() || dst_am.invalid())
33106 ri->d[rEXP1] = 0;
33107 else
33108 {
33109 11964 string formatstr;
33110
1/2
✓ Branch 0 taken 11964 times.
✗ Branch 1 not taken.
11964 ArrayH::getString(format_arrayptr, formatstr, MAX_ZC_ARRAY_SIZE);
33111
33112
3/4
✓ Branch 0 taken 319 times.
✓ Branch 1 taken 11645 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11964 times.
11964 string output = zs_sprintf(formatstr.c_str(), num_args, varg ? zspr_varg_getter : zspr_stack_getter);
33113
2/4
✓ Branch 0 taken 11964 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11964 times.
11964 if(ArrayH::setArray(dest_arrayptr, output, true) == SH::_Overflow)
33114 {
33115 Z_scripterrlog("Dest string supplied to 'sprintf()' not large enough and cannot be resized\n");
33116 ri->d[rEXP1] = ArrayH::strlen(dest_arrayptr);
33117 }
33118 11964 else ri->d[rEXP1] = output.size();
33119 11964 }
33120
2/2
✓ Branch 0 taken 11645 times.
✓ Branch 1 taken 319 times.
11964 if(varg)
33121 319 zs_vargs.clear();
33122 11964 }
33123 void FFScript::do_printfarr()
33124 {
33125 int32_t format_arrayptr = SH::read_stack(ri->sp + 1),
33126 args_arrayptr = SH::read_stack(ri->sp + 0);
33127 ArrayManager fmt_am(format_arrayptr);
33128 ArrayManager arg_am(args_arrayptr);
33129 if(!(fmt_am.invalid() || arg_am.invalid()))
33130 {
33131 auto num_args = arg_am.size();
33132 string formatstr;
33133 ArrayH::getString(format_arrayptr, formatstr, MAX_ZC_ARRAY_SIZE);
33134
33135 traceStr(zs_sprintf(formatstr.c_str(), num_args,
33136 [&](int32_t,int32_t next_arg)
33137 {
33138 return arg_am.get(next_arg);
33139 }));
33140 }
33141 }
33142 void FFScript::do_sprintfarr()
33143 {
33144 int32_t dest_arrayptr = SH::read_stack(ri->sp + 2),
33145 format_arrayptr = SH::read_stack(ri->sp + 1),
33146 args_arrayptr = SH::read_stack(ri->sp + 0);
33147 ArrayManager fmt_am(format_arrayptr);
33148 ArrayManager arg_am(args_arrayptr);
33149 ArrayManager dst_am(dest_arrayptr);
33150 if(fmt_am.invalid() || arg_am.invalid() || dst_am.invalid())
33151 ri->d[rEXP1] = 0;
33152 else
33153 {
33154 auto num_args = arg_am.size();
33155 string formatstr;
33156 ArrayH::getString(format_arrayptr, formatstr, MAX_ZC_ARRAY_SIZE);
33157
33158 string output = zs_sprintf(formatstr.c_str(), num_args,
33159 [&](int32_t,int32_t next_arg)
33160 {
33161 return arg_am.get(next_arg);
33162 });
33163
33164 if(ArrayH::setArray(dest_arrayptr, output, true) == SH::_Overflow)
33165 {
33166 Z_scripterrlog("Dest string supplied to 'sprintfa()' not large enough and cannot be resized\n");
33167 ri->d[rEXP1] = ArrayH::strlen(dest_arrayptr);
33168 }
33169 else ri->d[rEXP1] = output.size();
33170 }
33171 }
33172 1520226 void FFScript::do_varg_max()
33173 {
33174 1520226 int32_t num_args = zs_vargs.size();
33175 1520226 int32_t val = 0;
33176
1/2
✓ Branch 0 taken 1520226 times.
✗ Branch 1 not taken.
1520226 if (num_args > 0)
33177 1520226 val = zs_vargs.at(0);
33178
2/2
✓ Branch 0 taken 1520226 times.
✓ Branch 1 taken 1520226 times.
3040452 for(auto q = 1; q < num_args; ++q)
33179 {
33180 1520226 int32_t tval = zs_vargs.at(q);
33181
2/2
✓ Branch 0 taken 1232999 times.
✓ Branch 1 taken 287227 times.
1520226 if(tval > val) val = tval;
33182 1520226 }
33183 1520226 zs_vargs.clear();
33184 1520226 ri->d[rEXP1] = val;
33185 1520226 }
33186 140579 void FFScript::do_varg_min()
33187 {
33188 140579 int32_t num_args = zs_vargs.size();
33189 140579 int32_t val = 0;
33190
1/2
✓ Branch 0 taken 140579 times.
✗ Branch 1 not taken.
140579 if (num_args > 0)
33191 140579 val = zs_vargs.at(0);
33192
2/2
✓ Branch 0 taken 140579 times.
✓ Branch 1 taken 143253 times.
283832 for(auto q = 1; q < num_args; ++q)
33193 {
33194 143253 int32_t tval = zs_vargs.at(q);
33195
2/2
✓ Branch 0 taken 110082 times.
✓ Branch 1 taken 33171 times.
143253 if(tval < val) val = tval;
33196 143253 }
33197 140579 zs_vargs.clear();
33198 140579 ri->d[rEXP1] = val;
33199 140579 }
33200 5 void FFScript::do_varg_choose()
33201 {
33202 5 int32_t num_args = zs_vargs.size();
33203 5 int32_t val = 0;
33204
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(num_args > 0)
33205 {
33206 5 int32_t choice = zc_rand(num_args-1);
33207 5 val = zs_vargs.at(choice);
33208 5 }
33209 5 zs_vargs.clear();
33210 5 ri->d[rEXP1] = val;
33211 5 }
33212 30 void FFScript::do_varg_makearray(ScriptType type, const uint32_t UID, script_object_type object_type)
33213 {
33214 30 auto vargs = zs_vargs;
33215 30 zs_vargs.clear();
33216
33217 30 size_t size = vargs.size();
33218 30 ri->d[rEXP1] = 0;
33219
33220
2/4
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
30 if (ZScriptVersion::gc_arrays())
33221 {
33222
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 auto* array = script_arrays.create();
33223
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if (!array)
33224 return;
33225
33226 30 ZScriptArray &a = array->arr;
33227
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 a.Resize(size);
33228
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 a.setValid(true);
33229
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 a.setObjectType(object_type);
33230
33231
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 30 times.
76 for(size_t j = 0; j < size; ++j)
33232
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 a[j] = vargs[j]; //initialize array
33233
33234 30 ri->d[rEXP1] = array->id;
33235
33236 30 return;
33237 }
33238
33239 dword ptrval;
33240 for(ptrval = 1; localRAM[ptrval].Valid(); ptrval++) ;
33241
33242 if(ptrval >= NUM_ZSCRIPT_ARRAYS)
33243 {
33244 Z_scripterrlog("%d local arrays already in use, no more can be allocated\n", NUM_ZSCRIPT_ARRAYS-1);
33245 ptrval = 0;
33246 }
33247 else
33248 {
33249 ZScriptArray &a = localRAM[ptrval];
33250
33251 a.Resize(size);
33252 a.setValid(true);
33253
33254 for(size_t j = 0; j < size; ++j)
33255 a[j] = vargs[j]; //initialize array
33256
33257 arrayOwner[ptrval].clear();
33258 arrayOwner[ptrval].reown(type, UID);
33259 }
33260
33261 ri->d[rEXP1] = ptrval*10000;
33262
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 }
33263
33264 void FFScript::do_breakpoint()
33265 {
33266 // TODO: implement as `debugger;` statement when VS Code extension exists.
33267 }
33268
33269 12 void FFScript::do_tracenl()
33270 {
33271 12 safe_al_trace("\n");
33272
33273
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if ( console_enabled )
33274 {
33275 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
33276 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),"\n");
33277 }
33278 12 }
33279
33280
33281 215535 void FFScript::TraceScriptIDs(bool force_show_context)
33282 {
33283 if(DEVTIMESTAMP)
33284 {
33285 CConsoleLoggerEx console = zscript_coloured_console;
33286 bool cond = console_enabled;
33287
33288 char buf[256] = {0};
33289 //Calculate timestamp
33290 struct tm * tm_struct;
33291 time_t sysRTC;
33292 time (&sysRTC);
33293 tm_struct = localtime (&sysRTC);
33294
33295 sprintf(buf, "[%d:%d:%d] ", tm_struct->tm_hour, tm_struct->tm_min, tm_struct->tm_sec);
33296 //
33297
33298 al_trace("%s", buf);
33299 if ( cond ) {console.safeprint((CConsoleLoggerEx::COLOR_GREEN | CConsoleLoggerEx::COLOR_INTENSITY |
33300 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),buf); }
33301 }
33302
33303
4/4
✓ Branch 0 taken 169993 times.
✓ Branch 1 taken 45542 times.
✓ Branch 2 taken 40359 times.
✓ Branch 3 taken 5183 times.
215535 bool show_context = force_show_context || (get_qr(qr_TRACESCRIPTIDS) || DEVLOGGING);
33304
2/2
✓ Branch 0 taken 5183 times.
✓ Branch 1 taken 210352 times.
215535 if (show_context)
33305 {
33306 210352 CConsoleLoggerEx console = zscript_coloured_console;
33307 210352 bool cond = console_enabled;
33308 210352 char buf[256] = {0};
33309
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 210346 times.
210352 if(script_funcrun)
33310 {
33311
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 sprintf(buf, "Destructor(%d,%s): ", ri->thiskey, destructstr?destructstr->c_str():"UNKNOWN");
33312 6 }
33313
9/18
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 158845 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 30688 times.
✓ Branch 9 taken 53 times.
✓ Branch 10 taken 10 times.
✓ Branch 11 taken 94 times.
✓ Branch 12 taken 1648 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 18958 times.
✗ Branch 17 not taken.
210346 else switch(curScriptType)
33314 {
33315 case ScriptType::Global:
33316 {
33317
2/9
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 18930 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
18958 switch(curScriptNum)
33318 {
33319 case GLOBAL_SCRIPT_INIT:
33320
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
28 sprintf(buf, "Global Init(%s): ", globalmap[curScriptNum].scriptname.c_str());
33321 28 break;
33322 case GLOBAL_SCRIPT_GAME:
33323
1/2
✓ Branch 0 taken 18930 times.
✗ Branch 1 not taken.
18930 sprintf(buf, "Global Active(%s): ", globalmap[curScriptNum].scriptname.c_str());
33324 18930 break;
33325 case GLOBAL_SCRIPT_END:
33326 sprintf(buf, "Global Exit(%s): ", globalmap[curScriptNum].scriptname.c_str());
33327 break;
33328 case GLOBAL_SCRIPT_ONSAVELOAD:
33329 sprintf(buf, "Global SaveLoad(%s): ", globalmap[curScriptNum].scriptname.c_str());
33330 break;
33331 case GLOBAL_SCRIPT_ONLAUNCH:
33332 sprintf(buf, "Global Launch(%s): ", globalmap[curScriptNum].scriptname.c_str());
33333 break;
33334 case GLOBAL_SCRIPT_ONCONTGAME:
33335 sprintf(buf, "Global ContGame(%s): ", globalmap[curScriptNum].scriptname.c_str());
33336 break;
33337 case GLOBAL_SCRIPT_F6:
33338 sprintf(buf, "Global F6Menu(%s): ", globalmap[curScriptNum].scriptname.c_str());
33339 break;
33340 case GLOBAL_SCRIPT_ONSAVE:
33341 sprintf(buf, "Global Save(%s): ", globalmap[curScriptNum].scriptname.c_str());
33342 break;
33343 }
33344 18958 break;
33345 }
33346
33347 case ScriptType::Hero:
33348 {
33349 switch(curScriptNum)
33350 {
33351 case SCRIPT_HERO_INIT:
33352 sprintf(buf, "Hero Init(%s): ", playermap[curScriptNum-1].scriptname.c_str());
33353 break;
33354 case SCRIPT_HERO_ACTIVE:
33355 sprintf(buf, "Hero Active(%s): ", playermap[curScriptNum-1].scriptname.c_str());
33356 break;
33357 case SCRIPT_HERO_DEATH:
33358 sprintf(buf, "Hero Death(%s): ", playermap[curScriptNum-1].scriptname.c_str());
33359 break;
33360 case SCRIPT_HERO_WIN:
33361 sprintf(buf, "Hero Win(%s): ", playermap[curScriptNum-1].scriptname.c_str());
33362 break;
33363 }
33364 break;
33365 }
33366
33367 case ScriptType::Lwpn:
33368
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 sprintf(buf, "LWeapon(%u, %s): ", curScriptNum,lwpnmap[curScriptNum-1].scriptname.c_str());
33369 48 break;
33370
33371 case ScriptType::Ewpn:
33372 sprintf(buf, "EWeapon(%u, %s): ", curScriptNum,ewpnmap[curScriptNum-1].scriptname.c_str());
33373 break;
33374
33375 case ScriptType::NPC:
33376 sprintf(buf, "NPC(%u, %s): ", curScriptNum,npcmap[curScriptNum-1].scriptname.c_str());
33377 break;
33378
33379 case ScriptType::FFC:
33380
1/2
✓ Branch 0 taken 158845 times.
✗ Branch 1 not taken.
158845 sprintf(buf, "FFC(%u, %s): ", curScriptNum,ffcmap[curScriptNum-1].scriptname.c_str());
33381 158845 break;
33382
33383 case ScriptType::Item:
33384 sprintf(buf, "Item(%u, %s): ", curScriptNum,itemmap[curScriptNum-1].scriptname.c_str());
33385 break;
33386
33387 case ScriptType::OnMap:
33388 sprintf(buf, "DMapMap(%u, %s): ", curScriptNum,dmapmap[curScriptNum-1].scriptname.c_str());
33389 break;
33390 case ScriptType::ScriptedActiveSubscreen:
33391 sprintf(buf, "DMapASub(%u, %s): ", curScriptNum,dmapmap[curScriptNum-1].scriptname.c_str());
33392 break;
33393 case ScriptType::ScriptedPassiveSubscreen:
33394
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 sprintf(buf, "DMapPSub(%u, %s): ", curScriptNum,dmapmap[curScriptNum-1].scriptname.c_str());
33395 2 break;
33396 case ScriptType::DMap:
33397
1/2
✓ Branch 0 taken 30688 times.
✗ Branch 1 not taken.
30688 sprintf(buf, "DMap(%u, %s): ", curScriptNum,dmapmap[curScriptNum-1].scriptname.c_str());
33398 30688 break;
33399
33400 case ScriptType::ItemSprite:
33401
1/2
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
53 sprintf(buf, "ItemSprite(%u, %s): ", curScriptNum,itemspritemap[curScriptNum-1].scriptname.c_str());
33402 53 break;
33403
33404 case ScriptType::Screen:
33405
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 sprintf(buf, "Screen(%u, %s): ", curScriptNum,screenmap[curScriptNum-1].scriptname.c_str());
33406 10 break;
33407
33408 case ScriptType::Combo:
33409
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 sprintf(buf, "Combo(%u, %s): ", curScriptNum,comboscriptmap[curScriptNum-1].scriptname.c_str());
33410 94 break;
33411
33412 case ScriptType::Generic:
33413
1/2
✓ Branch 0 taken 1648 times.
✗ Branch 1 not taken.
1648 sprintf(buf, "Generic(%u, %s): ", curScriptNum,genericmap[curScriptNum-1].scriptname.c_str());
33414 1648 break;
33415
33416 case ScriptType::GenericFrozen:
33417 sprintf(buf, "GenericFRZ(%u, %s): ", curScriptNum,genericmap[curScriptNum-1].scriptname.c_str());
33418 break;
33419
33420 case ScriptType::EngineSubscreen:
33421 sprintf(buf, "Subscreen(%u, %s): ", curScriptNum,subscreenmap[curScriptNum-1].scriptname.c_str());
33422 break;
33423 }
33424
33425
1/2
✓ Branch 0 taken 210352 times.
✗ Branch 1 not taken.
210352 al_trace("%s", buf);
33426
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 210352 times.
210352 if ( cond )
33427 console.safeprint((CConsoleLoggerEx::COLOR_GREEN|CConsoleLoggerEx::COLOR_INTENSITY|
33428 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),buf);
33429 210352 }
33430 215535 }
33431
33432 2 void FFScript::do_cleartrace()
33433 {
33434 2 zc_trace_clear();
33435 2 clearConsole();
33436 2 }
33437
33438 3 string inttobase(word base, int32_t x, word mindigits)
33439 {
33440 static const char coeff[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
33441
33442 3 string s2;
33443
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 word digits = zc_max(mindigits - 1, word(floor(log(double(x)) / log(double(base)))));
33444
33445
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 3 times.
14 for(int32_t i = digits; i >= 0; i--)
33446 {
33447
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 s2 += coeff[word(floor(x / pow(double(base), i))) % base];
33448 11 }
33449
33450 3 return s2;
33451
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 }
33452
33453 3 void FFScript::do_tracetobase()
33454 {
33455 3 int32_t x = SH::read_stack(ri->sp + 2) / 10000;
33456 3 uint32_t base = vbound(SH::read_stack(ri->sp + 1) / 10000, 2, 36);
33457
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 uint32_t mindigits = zc_max(1, SH::read_stack(ri->sp) / 10000);
33458
33459
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 string s2 = x < 0 ? "-": "";
33460
33461
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 switch(base)
33462 {
33463 case 8:
33464 s2 += '0';
33465 break;
33466
33467 case 16:
33468 s2 += "0x";
33469 break;
33470 }
33471
33472
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 s2 += inttobase(base, int32_t(fabs(double(x))), mindigits);
33473
33474
2/3
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
3 switch(base)
33475 {
33476 case 8:
33477 case 10:
33478 case 16:
33479 2 break;
33480
33481 case 2:
33482
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 s2 += 'b';
33483 1 break;
33484
33485 default:
33486 std::stringstream ss;
33487 ss << " (Base " << base << ')';
33488 s2 += ss.str();
33489 break;
33490 }
33491
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 TraceScriptIDs();
33492
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 s2 += "\n";
33493
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 al_trace("%s", s2.c_str());
33494
33495
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if ( console_enabled )
33496 {
33497 zscript_coloured_console.safeprint((CConsoleLoggerEx::COLOR_WHITE |
33498 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK),s2.c_str());
33499 }
33500 3 }
33501
33502 //SRAM Functions
33503 void FFScript::write_dmaps(PACKFILE *f, int32_t vers_id)
33504 {
33505 word dmap_count=count_dmaps();
33506
33507 dmap_count=zc_min(dmap_count, 512);
33508 dmap_count=zc_min(dmap_count, MAXDMAPS-0);
33509
33510 //finally... section data
33511 if(!p_iputw(dmap_count,f))
33512 {
33513 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",5);
33514 }
33515
33516
33517 for(int32_t i=0; i<dmap_count; i++)
33518 {
33519 if(!p_putc(DMaps[i].map,f))
33520 {
33521 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",6);
33522 }
33523
33524 if(!p_iputw(DMaps[i].level,f))
33525 {
33526 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",7);
33527 }
33528
33529 if(!p_putc(DMaps[i].xoff,f))
33530 {
33531 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",8);
33532 }
33533
33534 if(!p_putc(DMaps[i].compass,f))
33535 {
33536 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",9);
33537 }
33538
33539 if(!p_iputw(DMaps[i].color,f))
33540 {
33541 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",10);
33542 }
33543
33544 if(!p_putc(DMaps[i].midi,f))
33545 {
33546 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",11);
33547 }
33548
33549 if(!p_putc(DMaps[i].cont,f))
33550 {
33551 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",12);
33552 }
33553
33554 if(!p_putc(DMaps[i].type,f))
33555 {
33556 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",13);
33557 }
33558
33559 for(int32_t j=0; j<8; j++)
33560 {
33561 if(!p_putc(DMaps[i].grid[j],f))
33562 {
33563 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",14);
33564 }
33565 }
33566
33567 //16
33568 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name),f))
33569 {
33570 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",15);
33571 }
33572
33573 if(!p_putwstr(DMaps[i].title,f))
33574 {
33575 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",16);
33576 }
33577
33578 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro),f))
33579 {
33580 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",17);
33581 }
33582
33583 if(!p_iputl(DMaps[i].minimap_tile[0],f))
33584 {
33585 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",18);
33586 }
33587
33588 if(!p_putc(DMaps[i].minimap_cset[0],f))
33589 {
33590 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",19);
33591 }
33592
33593 if(!p_iputl(DMaps[i].minimap_tile[1],f))
33594 {
33595 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",20);
33596 }
33597
33598 if(!p_putc(DMaps[i].minimap_cset[1],f))
33599 {
33600 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",21);
33601 }
33602
33603 if(!p_iputl(DMaps[i].largemap_tile[0],f))
33604 {
33605 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",22);
33606 }
33607
33608 if(!p_putc(DMaps[i].largemap_cset[0],f))
33609 {
33610 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",23);
33611 }
33612
33613 if(!p_iputl(DMaps[i].largemap_tile[1],f))
33614 {
33615 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",24);
33616 }
33617
33618 if(!p_putc(DMaps[i].largemap_cset[1],f))
33619 {
33620 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",25);
33621 }
33622
33623 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic),f))
33624 {
33625 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",26);
33626 }
33627
33628 if(!p_putc(DMaps[i].tmusictrack,f))
33629 {
33630 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",25);
33631 }
33632
33633 if(!p_putc(DMaps[i].active_subscreen,f))
33634 {
33635 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",26);
33636 }
33637
33638 if(!p_putc(DMaps[i].passive_subscreen,f))
33639 {
33640 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",27);
33641 }
33642
33643 byte disabled[32];
33644 memset(disabled,0,32);
33645
33646 for(int32_t j=0; j<MAXITEMS; j++)
33647 {
33648 if(DMaps[i].disableditems[j])
33649 {
33650 disabled[j/8] |= (1 << (j%8));
33651 }
33652 }
33653
33654 if(!pfwrite(disabled,32,f))
33655 {
33656 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",28);
33657 }
33658
33659 if(!p_iputl(DMaps[i].flags,f))
33660 {
33661 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",29);
33662 }
33663 if(!p_putc(DMaps[i].sideview,f))
33664 {
33665 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",30);
33666 }
33667 if(!p_iputw(DMaps[i].script,f))
33668 {
33669 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",31);
33670 }
33671 for ( int32_t q = 0; q < 8; q++ )
33672 {
33673 if(!p_iputl(DMaps[i].initD[q],f))
33674 {
33675 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",32);
33676 }
33677
33678 }
33679 for ( int32_t q = 0; q < 8; q++ )
33680 {
33681 for ( int32_t w = 0; w < 65; w++ )
33682 {
33683 if (!p_putc(DMaps[i].initD_label[q][w],f))
33684 {
33685 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",33);
33686 }
33687 }
33688 }
33689 }
33690 }
33691 void FFScript::read_dmaps(PACKFILE *f, int32_t vers_id)
33692 {
33693 word dmap_count=count_dmaps();
33694
33695 dmap_count=zc_min(dmap_count, 512);
33696 dmap_count=zc_min(dmap_count, MAXDMAPS-0);
33697
33698 //finally... section data
33699 if(!p_igetw(&dmap_count,f))
33700 {
33701 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",5);
33702 }
33703
33704
33705 for(int32_t i=0; i<dmap_count; i++)
33706 {
33707 if(!p_getc(&DMaps[i].map,f))
33708 {
33709 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",6);
33710 }
33711
33712 if(!p_igetw(&DMaps[i].level,f))
33713 {
33714 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",7);
33715 }
33716
33717 if(!p_getc(&DMaps[i].xoff,f))
33718 {
33719 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",8);
33720 }
33721
33722 if(!p_getc(&DMaps[i].compass,f))
33723 {
33724 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",9);
33725 }
33726
33727 if(!p_igetw(&DMaps[i].color,f))
33728 {
33729 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",10);
33730 }
33731
33732 if(!p_getc(&DMaps[i].midi,f))
33733 {
33734 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",11);
33735 }
33736
33737 if(!p_getc(&DMaps[i].cont,f))
33738 {
33739 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",12);
33740 }
33741
33742 if(!p_getc(&DMaps[i].type,f))
33743 {
33744 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",13);
33745 }
33746
33747 for(int32_t j=0; j<8; j++)
33748 {
33749 if(!p_getc(&DMaps[i].grid[j],f))
33750 {
33751 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",14);
33752 }
33753 }
33754
33755 //16
33756 if(!pfread((&DMaps[i].name),sizeof(DMaps[0].name),f))
33757 {
33758 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",15);
33759 }
33760
33761 if (!p_getwstr(&DMaps[i].title, f))
33762 {
33763 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",16);
33764 }
33765
33766 if(!pfread((&DMaps[i].intro),sizeof(DMaps[0].intro),f))
33767 {
33768 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",17);
33769 }
33770
33771 if(!p_igetl(&DMaps[i].minimap_tile[0],f))
33772 {
33773 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",18);
33774 }
33775
33776 if(!p_getc(&DMaps[i].minimap_cset[0],f))
33777 {
33778 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",19);
33779 }
33780
33781 if(!p_igetl(&DMaps[i].minimap_tile[1],f))
33782 {
33783 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",20);
33784 }
33785
33786 if(!p_getc(&DMaps[i].minimap_cset[1],f))
33787 {
33788 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",21);
33789 }
33790
33791 if(!p_igetl(&DMaps[i].largemap_tile[0],f))
33792 {
33793 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",22);
33794 }
33795
33796 if(!p_getc(&DMaps[i].largemap_cset[0],f))
33797 {
33798 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",23);
33799 }
33800
33801 if(!p_igetl(&DMaps[i].largemap_tile[1],f))
33802 {
33803 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",24);
33804 }
33805
33806 if(!p_getc(&DMaps[i].largemap_cset[1],f))
33807 {
33808 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",25);
33809 }
33810
33811 if(!pfread((&DMaps[i].tmusic),sizeof(DMaps[0].tmusic),f))
33812 {
33813 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",26);
33814 }
33815
33816 if(!p_getc(&DMaps[i].tmusictrack,f))
33817 {
33818 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",25);
33819 }
33820
33821 if(!p_getc(&DMaps[i].active_subscreen,f))
33822 {
33823 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",26);
33824 }
33825
33826 if(!p_getc(&DMaps[i].passive_subscreen,f))
33827 {
33828 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",27);
33829 }
33830
33831 byte disabled[32];
33832 memset(disabled,0,32);
33833
33834 for(int32_t j=0; j<MAXITEMS; j++)
33835 {
33836 if(&DMaps[i].disableditems[j])
33837 {
33838 disabled[j/8] |= (1 << (j%8));
33839 }
33840 }
33841
33842 if(!pfread(disabled,32,f))
33843 {
33844 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",28);
33845 }
33846
33847 if(!p_igetl(&DMaps[i].flags,f))
33848 {
33849 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",29);
33850 }
33851 if(!p_getc(&DMaps[i].sideview,f))
33852 {
33853 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",30);
33854 }
33855 if(!p_igetw(&DMaps[i].script,f))
33856 {
33857 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",31);
33858 }
33859 for ( int32_t q = 0; q < 8; q++ )
33860 {
33861 if(!p_igetl(&DMaps[i].initD[q],f))
33862 {
33863 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",32);
33864 }
33865
33866 }
33867 for ( int32_t q = 0; q < 8; q++ )
33868 {
33869 for ( int32_t w = 0; w < 65; w++ )
33870 {
33871 if (!p_getc(&DMaps[i].initD_label[q][w],f))
33872 {
33873 Z_scripterrlog("do_savegamestructs FAILED to read DMAP NODE: %d",33);
33874 }
33875 }
33876 }
33877 }
33878 }
33879
33880
33881
33882 void FFScript::read_combos(PACKFILE *f, int32_t version_id)
33883 {
33884
33885 word combos_used = 0;
33886
33887 if(!p_igetw(&combos_used,f))
33888 {
33889 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",5);
33890 }
33891
33892 for(int32_t i=0; i<combos_used; i++)
33893 {
33894 if(!p_igetl(&combobuf[i].tile,f))
33895 {
33896 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",6);
33897 }
33898
33899 if(!p_getc(&combobuf[i].flip,f))
33900 {
33901 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",7);
33902 }
33903
33904 if(!p_getc(&combobuf[i].walk,f))
33905 {
33906 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",8);
33907 }
33908
33909 if(!p_getc(&combobuf[i].type,f))
33910 {
33911 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",9);
33912 }
33913
33914 if(!p_getc(&combobuf[i].csets,f))
33915 {
33916 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",10);
33917 }
33918
33919 if(!p_getc(&combobuf[i].frames,f))
33920 {
33921 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",11);
33922 }
33923
33924 if(!p_getc(&combobuf[i].speed,f))
33925 {
33926 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",12);
33927 }
33928
33929 if(!p_igetw(&combobuf[i].nextcombo,f))
33930 {
33931 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",13);
33932 }
33933
33934 if(!p_getc(&combobuf[i].nextcset,f))
33935 {
33936 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",14);
33937 }
33938
33939 if(!p_getc(&combobuf[i].flag,f))
33940 {
33941 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",15);
33942 }
33943
33944 if(!p_getc(&combobuf[i].skipanim,f))
33945 {
33946 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",16);
33947 }
33948
33949 if(!p_igetw(&combobuf[i].nexttimer,f))
33950 {
33951 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",17);
33952 }
33953
33954 if(!p_getc(&combobuf[i].skipanimy,f))
33955 {
33956 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",18);
33957 }
33958
33959 if(!p_getc(&combobuf[i].animflags,f))
33960 {
33961 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",19);
33962 }
33963
33964 for ( int32_t q = 0; q < NUM_COMBO_ATTRIBUTES; q++ )
33965 {
33966 if(!p_igetl(&combobuf[i].attributes[q],f))
33967 {
33968 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",20);
33969 }
33970 }
33971 if(!p_igetl(&combobuf[i].usrflags,f))
33972 {
33973 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",21);
33974 }
33975 if(combobuf[i].triggers.empty())
33976 combobuf[i].triggers.emplace_back();
33977 for ( int32_t q = 0; q < 6; q++ )
33978 {
33979 if(!p_igetl(&combobuf[i].triggers[0].triggerflags[q],f))
33980 {
33981 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",22);
33982 }
33983 }
33984
33985 if(!p_igetl(&combobuf[i].triggers[0].triggerlevel,f))
33986 {
33987 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",23);
33988 }
33989 for ( int32_t q = 0; q < 11; q++ )
33990 {
33991 if(!p_getc(&combobuf[i].label[q],f))
33992 {
33993 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",24);
33994 }
33995 }
33996 for ( int32_t q = 0; q < NUM_COMBO_ATTRIBUTES; q++ )
33997 {
33998 if(!p_getc(&combobuf[i].attribytes[q],f))
33999 {
34000 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",25);
34001 }
34002 }
34003 if(!p_igetw(&combobuf[i].script,f))
34004 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",26);
34005 for ( int32_t q = 0; q < 2; q++ )
34006 {
34007 if(!p_igetl(&combobuf[i].initd[q],f))
34008 {
34009 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",27);
34010 }
34011 }
34012 if(!p_igetl(&combobuf[i].o_tile,f))
34013 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",28);
34014 if(!p_getc(&combobuf[i].cur_frame,f))
34015 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",29);
34016 if(!p_getc(&combobuf[i].aclk,f))
34017 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",30);
34018 }
34019
34020 combo_caches::refresh();
34021 }
34022
34023 void FFScript::write_combos(PACKFILE *f, int32_t version_id)
34024 {
34025
34026 word combos_used = 0;
34027
34028 //finally... section data
34029 combos_used=count_combos()-0;
34030 combos_used=zc_min(combos_used, MAXCOMBOS);
34031
34032 if(!p_iputw(combos_used,f))
34033 {
34034 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",5);
34035 }
34036
34037 for(int32_t i=0; i<combos_used; i++)
34038 {
34039 if(!p_iputl(combobuf[i].tile,f))
34040 {
34041 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",6);
34042 }
34043
34044 if(!p_putc(combobuf[i].flip,f))
34045 {
34046 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",7);
34047 }
34048
34049 if(!p_putc(combobuf[i].walk,f))
34050 {
34051 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",8);
34052 }
34053
34054 if(!p_putc(combobuf[i].type,f))
34055 {
34056 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",9);
34057 }
34058
34059 if(!p_putc(combobuf[i].csets,f))
34060 {
34061 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",10);
34062 }
34063
34064 if(!p_putc(combobuf[i].frames,f))
34065 {
34066 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",11);
34067 }
34068
34069 if(!p_putc(combobuf[i].speed,f))
34070 {
34071 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",12);
34072 }
34073
34074 if(!p_iputw(combobuf[i].nextcombo,f))
34075 {
34076 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",13);
34077 }
34078
34079 if(!p_putc(combobuf[i].nextcset,f))
34080 {
34081 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",14);
34082 }
34083
34084 if(!p_putc(combobuf[i].flag,f))
34085 {
34086 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",15);
34087 }
34088
34089 if(!p_putc(combobuf[i].skipanim,f))
34090 {
34091 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",16);
34092 }
34093
34094 if(!p_iputw(combobuf[i].nexttimer,f))
34095 {
34096 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",17);
34097 }
34098
34099 if(!p_putc(combobuf[i].skipanimy,f))
34100 {
34101 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",18);
34102 }
34103
34104 if(!p_putc(combobuf[i].animflags,f))
34105 {
34106 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",19);
34107 }
34108
34109 for ( int32_t q = 0; q < NUM_COMBO_ATTRIBUTES; q++ )
34110 {
34111 if(!p_iputl(combobuf[i].attributes[q],f))
34112 {
34113 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",20);
34114 }
34115 }
34116 if(!p_iputl(combobuf[i].usrflags,f))
34117 {
34118 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",21);
34119 }
34120 if(combobuf[i].triggers.empty())
34121 combobuf[i].triggers.emplace_back();
34122 for ( int32_t q = 0; q < 6; q++ )
34123 {
34124 if(!p_iputl(combobuf[i].triggers[0].triggerflags[q],f))
34125 {
34126 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",22);
34127 }
34128 }
34129
34130 if(!p_iputl(combobuf[i].triggers[0].triggerlevel,f))
34131 {
34132 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",23);
34133 }
34134 for ( int32_t q = 0; q < 11; q++ )
34135 {
34136 if(!p_putc(combobuf[i].label[q],f))
34137 {
34138 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",24);
34139 }
34140 }
34141 for ( int32_t q = 0; q < NUM_COMBO_ATTRIBUTES; q++ )
34142 {
34143 if(!p_putc(combobuf[i].attribytes[q],f))
34144 {
34145 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",25);
34146 }
34147 }
34148 if(!p_iputw(combobuf[i].script,f))
34149 {
34150 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",26);
34151 }
34152 for ( int32_t q = 0; q < 2; q++ )
34153 {
34154 if(!p_iputl(combobuf[i].initd[q],f))
34155 {
34156 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",27);
34157 }
34158 }
34159 if(!p_iputl(combobuf[i].o_tile,f))
34160 {
34161 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",28);
34162 }
34163 if(!p_putc(combobuf[i].cur_frame,f))
34164 {
34165 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",29);
34166 }
34167 if(!p_putc(combobuf[i].aclk,f))
34168 {
34169 Z_scripterrlog("do_savegamestructs FAILED to read COMBO NODE: %d",30);
34170 }
34171
34172 }
34173 }
34174 void FFScript::read_weaponsprtites(PACKFILE *f, int32_t vers_id)
34175 {
34176 for(int32_t i=0; i<MAXWPNS; i++)
34177 {
34178 word oldtile = 0;
34179 if(!p_igetw(&oldtile,f))
34180 {
34181 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",6);
34182 }
34183
34184 if(!p_getc(&wpnsbuf[i].misc,f))
34185 {
34186 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",7);
34187 }
34188
34189 if(!p_getc(&wpnsbuf[i].csets,f))
34190 {
34191 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",8);
34192 }
34193
34194 if(!p_getc(&wpnsbuf[i].frames,f))
34195 {
34196 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",9);
34197 }
34198
34199 if(!p_getc(&wpnsbuf[i].speed,f))
34200 {
34201 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",10);
34202 }
34203
34204 if(!p_getc(&wpnsbuf[i].type,f))
34205 {
34206 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",11);
34207 }
34208
34209 if(!p_igetw(&wpnsbuf[i].script,f))
34210 {
34211 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",12);
34212 }
34213
34214 if(!p_igetl(&wpnsbuf[i].tile,f))
34215 {
34216 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",12);
34217 }
34218 }
34219 }
34220 void FFScript::write_weaponsprtites(PACKFILE *f, int32_t vers_id)
34221 {
34222 for(int32_t i=0; i<MAXWPNS; i++)
34223 {
34224 if(!p_iputw(wpnsbuf[i].tile,f))
34225 {
34226 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",6);
34227 }
34228
34229 if(!p_putc(wpnsbuf[i].misc,f))
34230 {
34231 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",7);
34232 }
34233
34234 if(!p_putc(wpnsbuf[i].csets,f))
34235 {
34236 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",8);
34237 }
34238
34239 if(!p_putc(wpnsbuf[i].frames,f))
34240 {
34241 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",9);
34242 }
34243
34244 if(!p_putc(wpnsbuf[i].speed,f))
34245 {
34246 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",10);
34247 }
34248
34249 if(!p_putc(wpnsbuf[i].type,f))
34250 {
34251 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",11);
34252 }
34253
34254 if(!p_iputw(wpnsbuf[i].script,f))
34255 {
34256 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",12);
34257 }
34258
34259 if(!p_iputl(wpnsbuf[i].tile,f))
34260 {
34261 Z_scripterrlog("do_savegamestructs FAILED to read WPNSPRITE NODE: %d",12);
34262 }
34263 }
34264 }
34265
34266
34267 void FFScript::read_enemies(PACKFILE *f, int32_t vers_id)
34268 {
34269 if ( !f ) return;
34270 for(int32_t i=0; i<MAXGUYS; i++)
34271 {
34272 uint32_t flags1;
34273 uint32_t flags2;
34274 if (!p_igetl(&(flags1), f))
34275 {
34276 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 6);
34277 }
34278 if (!p_igetl(&(flags2), f))
34279 {
34280 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 7);;
34281 }
34282 guysbuf[i].flags = guy_flags(flags1) | guy_flags(uint64_t(flags2) << 32ULL);
34283
34284 if(!p_igetl(&guysbuf[i].tile,f))
34285 {
34286 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",8);
34287 }
34288
34289 if(!p_getc(&guysbuf[i].width,f))
34290 {
34291 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",9);
34292 }
34293
34294 if(!p_getc(&guysbuf[i].height,f))
34295 {
34296 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",10);
34297 }
34298
34299 if(!p_igetl(&guysbuf[i].s_tile,f))
34300 {
34301 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",11);
34302 }
34303
34304 if(!p_getc(&guysbuf[i].s_width,f))
34305 {
34306 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",12);
34307 }
34308
34309 if(!p_getc(&guysbuf[i].s_height,f))
34310 {
34311 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",13);
34312 }
34313
34314 if(!p_igetl(&guysbuf[i].e_tile,f))
34315 {
34316 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",14);
34317 }
34318
34319 if(!p_getc(&guysbuf[i].e_width,f))
34320 {
34321 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",15);
34322 }
34323
34324 if(!p_getc(&guysbuf[i].e_height,f))
34325 {
34326 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",16);
34327 }
34328
34329 if(!p_igetw(&guysbuf[i].hp,f))
34330 {
34331 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",17);
34332 }
34333
34334 if(!p_igetw(&guysbuf[i].family,f))
34335 {
34336 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",18);
34337 }
34338
34339 if(!p_igetw(&guysbuf[i].cset,f))
34340 {
34341 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",19);
34342 }
34343
34344 if(!p_igetw(&guysbuf[i].anim,f))
34345 {
34346 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",20);
34347 }
34348
34349 if(!p_igetw(&guysbuf[i].e_anim,f))
34350 {
34351 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",21);
34352 }
34353
34354 if(!p_igetw(&guysbuf[i].frate,f))
34355 {
34356 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",22);
34357 }
34358
34359 if(!p_igetw(&guysbuf[i].e_frate,f))
34360 {
34361 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",23);
34362 }
34363
34364 if(!p_igetw(&guysbuf[i].dp,f))
34365 {
34366 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",24);
34367 }
34368
34369 if(!p_igetw(&guysbuf[i].wdp,f))
34370 {
34371 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",25);
34372 }
34373
34374 if(!p_igetw(&guysbuf[i].weapon,f))
34375 {
34376 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",26);
34377 }
34378
34379 if(!p_igetw(&guysbuf[i].rate,f))
34380 {
34381 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",27);
34382 }
34383
34384 if(!p_igetw(&guysbuf[i].hrate,f))
34385 {
34386 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",28);
34387 }
34388
34389 if(!p_igetw(&guysbuf[i].step,f))
34390 {
34391 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",29);
34392 }
34393
34394 if(!p_igetw(&guysbuf[i].homing,f))
34395 {
34396 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",30);
34397 }
34398
34399 if(!p_igetw(&guysbuf[i].grumble,f))
34400 {
34401 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",31);
34402 }
34403
34404 if(!p_igetw(&guysbuf[i].item_set,f))
34405 {
34406 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",32);
34407 }
34408 //misc 1-10
34409 for (int q = 0; q < 10; ++q)
34410 {
34411 if (!p_igetl(&guysbuf[i].attributes[q], f))
34412 {
34413 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 33 + q);
34414 }
34415 }
34416
34417 if(!p_igetw(&guysbuf[i].bgsfx,f))
34418 {
34419 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",43);
34420 }
34421
34422 if(!p_igetw(&guysbuf[i].bosspal,f))
34423 {
34424 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",44);
34425 }
34426
34427 if(!p_igetw(&guysbuf[i].extend,f))
34428 {
34429 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",45);
34430 }
34431
34432 for(int32_t j=0; j < edefLAST; j++)
34433 {
34434 if(!p_getc(&guysbuf[i].defense[j],f))
34435 {
34436 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",46);
34437 }
34438 }
34439
34440 if(!p_getc(&guysbuf[i].hitsfx,f))
34441 {
34442 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",47);
34443 }
34444
34445 if(!p_getc(&guysbuf[i].deadsfx,f))
34446 {
34447 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",48);
34448 }
34449 //misc 11-12
34450 for (int q = 0; q < 2; ++q)
34451 {
34452 if (!p_igetl(&guysbuf[i].attributes[10+q], f))
34453 {
34454 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 49 + q);
34455 }
34456 }
34457
34458 //New 2.6 defences
34459 for(int32_t j=edefLAST; j < edefLAST255; j++)
34460 {
34461 if(!p_getc(&guysbuf[i].defense[j],f))
34462 {
34463 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",51);
34464 }
34465 }
34466
34467 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
34468 if(!p_igetl(&guysbuf[i].txsz,f))
34469 {
34470 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",52);
34471 }
34472 if(!p_igetl(&guysbuf[i].tysz,f))
34473 {
34474 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",53);
34475 }
34476 if(!p_igetl(&guysbuf[i].hxsz,f))
34477 {
34478 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",54);
34479 }
34480 if(!p_igetl(&guysbuf[i].hysz,f))
34481 {
34482 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",55);
34483 }
34484 if(!p_igetl(&guysbuf[i].hzsz,f))
34485 {
34486 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",56);
34487 }
34488 // These are not fixed types, but ints, so they are safe to use here.
34489 if(!p_igetl(&guysbuf[i].hxofs,f))
34490 {
34491 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",57);
34492 }
34493 if(!p_igetl(&guysbuf[i].hyofs,f))
34494 {
34495 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",58);
34496 }
34497 if(!p_igetl(&guysbuf[i].xofs,f))
34498 {
34499 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",59);
34500 }
34501 if(!p_igetl(&guysbuf[i].yofs,f))
34502 {
34503 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",60);
34504 }
34505 if(!p_igetl(&guysbuf[i].zofs,f))
34506 {
34507 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",61);
34508 }
34509 if(!p_igetl(&guysbuf[i].wpnsprite,f))
34510 {
34511 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",62);
34512 }
34513 if(!p_igetl(&guysbuf[i].SIZEflags,f))
34514 {
34515 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",63);
34516 }
34517 if(!p_igetl(&guysbuf[i].frozentile,f))
34518 {
34519 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",64);
34520 }
34521 if(!p_igetl(&guysbuf[i].frozencset,f))
34522 {
34523 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",65);
34524 }
34525 if(!p_igetl(&guysbuf[i].frozenclock,f))
34526 {
34527 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",66);
34528 }
34529
34530 for ( int32_t q = 0; q < 10; q++ )
34531 {
34532 if(!p_igetw(&guysbuf[i].frozenmisc[q],f))
34533 {
34534 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",67);
34535 }
34536 }
34537 if(!p_igetw(&guysbuf[i].firesfx,f))
34538 {
34539 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",68);
34540 }
34541 //misc 16->32
34542 for (int q = 0; q < 17; ++q)
34543 {
34544 if (!p_igetl(&guysbuf[i].attributes[15 + q], f))
34545 {
34546 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 69 + q);
34547 }
34548 }
34549 for ( int32_t q = 0; q < 32; q++ )
34550 {
34551 if(!p_igetl(&guysbuf[i].movement[q],f))
34552 {
34553 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",86);
34554 }
34555 }
34556 for ( int32_t q = 0; q < 32; q++ )
34557 {
34558 if(!p_igetl(&guysbuf[i].new_weapon[q],f))
34559 {
34560 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",87);
34561 }
34562 }
34563 if(!p_igetw(&guysbuf[i].script,f))
34564 {
34565 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",88);
34566 }
34567 for ( int32_t q = 0; q < 8; q++ )
34568 {
34569 if(!p_igetl(&guysbuf[i].initD[q],f))
34570 {
34571 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",89);
34572 }
34573 }
34574 if(!p_igetl(&guysbuf[i].editorflags,f))
34575 {
34576 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",91);
34577 }
34578 //somehow forgot these in the older builds -Z
34579 for (int q = 0; q < 3; ++q)
34580 {
34581 if (!p_igetl(&guysbuf[i].attributes[12 + q], f))
34582 {
34583 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d", 92 + q);
34584 }
34585 }
34586
34587 //Enemy Editor InitD[] labels
34588 for ( int32_t q = 0; q < 8; q++ )
34589 {
34590 for ( int32_t w = 0; w < 65; w++ )
34591 {
34592 if(!p_getc(&guysbuf[i].initD_label[q][w],f))
34593 {
34594 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",95);
34595 }
34596 }
34597 for ( int32_t w = 0; w < 65; w++ )
34598 {
34599 if(!p_getc(&guysbuf[i].weapon_initD_label[q][w],f))
34600 {
34601 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",96);
34602 }
34603 }
34604 }
34605 if(!p_igetw(&guysbuf[i].weaponscript,f))
34606 {
34607 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",97);
34608 }
34609 //eweapon initD
34610 for ( int32_t q = 0; q < 8; q++ )
34611 {
34612 if(!p_igetl(&guysbuf[i].weap_initiald[q],f))
34613 {
34614 Z_scripterrlog("do_savegamestructs FAILED to read GUY NODE: %d",98);
34615 }
34616 }
34617
34618
34619 }
34620 }
34621
34622 void FFScript::write_enemies(PACKFILE *f, int32_t vers_id)
34623 {
34624 if ( !f ) return;
34625 for(int32_t i=0; i<MAXGUYS; i++)
34626 {
34627 uint32_t flags1 = uint32_t(guysbuf[i].flags);
34628 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
34629 if (!p_iputl(flags1, f))
34630 {
34631 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 6);
34632 }
34633 if (!p_iputl(flags2, f))
34634 {
34635 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 7);
34636 }
34637
34638 if(!p_iputl(guysbuf[i].tile,f))
34639 {
34640 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",8);
34641 }
34642
34643 if(!p_putc(guysbuf[i].width,f))
34644 {
34645 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",9);
34646 }
34647
34648 if(!p_putc(guysbuf[i].height,f))
34649 {
34650 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",10);
34651 }
34652
34653 if(!p_iputl(guysbuf[i].s_tile,f))
34654 {
34655 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",11);
34656 }
34657
34658 if(!p_putc(guysbuf[i].s_width,f))
34659 {
34660 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",12);
34661 }
34662
34663 if(!p_putc(guysbuf[i].s_height,f))
34664 {
34665 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",13);
34666 }
34667
34668 if(!p_iputl(guysbuf[i].e_tile,f))
34669 {
34670 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",14);
34671 }
34672
34673 if(!p_putc(guysbuf[i].e_width,f))
34674 {
34675 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",15);
34676 }
34677
34678 if(!p_putc(guysbuf[i].e_height,f))
34679 {
34680 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",16);
34681 }
34682
34683 if(!p_iputw(guysbuf[i].hp,f))
34684 {
34685 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",17);
34686 }
34687
34688 if(!p_iputw(guysbuf[i].family,f))
34689 {
34690 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",18);
34691 }
34692
34693 if(!p_iputw(guysbuf[i].cset,f))
34694 {
34695 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",19);
34696 }
34697
34698 if(!p_iputw(guysbuf[i].anim,f))
34699 {
34700 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",20);
34701 }
34702
34703 if(!p_iputw(guysbuf[i].e_anim,f))
34704 {
34705 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",21);
34706 }
34707
34708 if(!p_iputw(guysbuf[i].frate,f))
34709 {
34710 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",22);
34711 }
34712
34713 if(!p_iputw(guysbuf[i].e_frate,f))
34714 {
34715 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",23);
34716 }
34717
34718 if(!p_iputw(guysbuf[i].dp,f))
34719 {
34720 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",24);
34721 }
34722
34723 if(!p_iputw(guysbuf[i].wdp,f))
34724 {
34725 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",25);
34726 }
34727
34728 if(!p_iputw(guysbuf[i].weapon,f))
34729 {
34730 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",26);
34731 }
34732
34733 if(!p_iputw(guysbuf[i].rate,f))
34734 {
34735 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",27);
34736 }
34737
34738 if(!p_iputw(guysbuf[i].hrate,f))
34739 {
34740 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",28);
34741 }
34742
34743 if(!p_iputw(guysbuf[i].step,f))
34744 {
34745 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",29);
34746 }
34747
34748 if(!p_iputw(guysbuf[i].homing,f))
34749 {
34750 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",30);
34751 }
34752
34753 if(!p_iputw(guysbuf[i].grumble,f))
34754 {
34755 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",31);
34756 }
34757
34758 if(!p_iputw(guysbuf[i].item_set,f))
34759 {
34760 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",32);
34761 }
34762
34763 //misc 1-10
34764 for (int q = 0; q < 10; ++q)
34765 {
34766 if (!p_iputl(guysbuf[i].attributes[q], f))
34767 {
34768 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 33+q);
34769 }
34770 }
34771
34772 if(!p_iputw(guysbuf[i].bgsfx,f))
34773 {
34774 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",43);
34775 }
34776
34777 if(!p_iputw(guysbuf[i].bosspal,f))
34778 {
34779 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",44);
34780 }
34781
34782 if(!p_iputw(guysbuf[i].extend,f))
34783 {
34784 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",45);
34785 }
34786
34787 for(int32_t j=0; j < edefLAST; j++)
34788 {
34789 if(!p_putc(guysbuf[i].defense[j],f))
34790 {
34791 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",46);
34792 }
34793 }
34794
34795 if(!p_putc(guysbuf[i].hitsfx,f))
34796 {
34797 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",47);
34798 }
34799
34800 if(!p_putc(guysbuf[i].deadsfx,f))
34801 {
34802 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",48);
34803 }
34804
34805 //misc 11-12
34806 for (int q = 0; q < 2; ++q)
34807 {
34808 if (!p_iputl(guysbuf[i].attributes[10+q], f))
34809 {
34810 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 49 + q);
34811 }
34812 }
34813
34814 //New 2.6 defences
34815 for(int32_t j=edefLAST; j < edefLAST255; j++)
34816 {
34817 if(!p_putc(guysbuf[i].defense[j],f))
34818 {
34819 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",51);
34820 }
34821 }
34822
34823 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
34824 if(!p_iputl(guysbuf[i].txsz,f))
34825 {
34826 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",52);
34827 }
34828 if(!p_iputl(guysbuf[i].tysz,f))
34829 {
34830 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",53);
34831 }
34832 if(!p_iputl(guysbuf[i].hxsz,f))
34833 {
34834 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",54);
34835 }
34836 if(!p_iputl(guysbuf[i].hysz,f))
34837 {
34838 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",55);
34839 }
34840 if(!p_iputl(guysbuf[i].hzsz,f))
34841 {
34842 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",56);
34843 }
34844 // These are not fixed types, but ints, so they are safe to use here.
34845 if(!p_iputl(guysbuf[i].hxofs,f))
34846 {
34847 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",57);
34848 }
34849 if(!p_iputl(guysbuf[i].hyofs,f))
34850 {
34851 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",58);
34852 }
34853 if(!p_iputl(guysbuf[i].xofs,f))
34854 {
34855 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",59);
34856 }
34857 if(!p_iputl(guysbuf[i].yofs,f))
34858 {
34859 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",60);
34860 }
34861 if(!p_iputl(guysbuf[i].zofs,f))
34862 {
34863 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",61);
34864 }
34865 if(!p_iputl(guysbuf[i].wpnsprite,f))
34866 {
34867 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",62);
34868 }
34869 if(!p_iputl(guysbuf[i].SIZEflags,f))
34870 {
34871 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",63);
34872 }
34873 if(!p_iputl(guysbuf[i].frozentile,f))
34874 {
34875 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",64);
34876 }
34877 if(!p_iputl(guysbuf[i].frozencset,f))
34878 {
34879 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",65);
34880 }
34881 if(!p_iputl(guysbuf[i].frozenclock,f))
34882 {
34883 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",66);
34884 }
34885
34886 for ( int32_t q = 0; q < 10; q++ )
34887 {
34888 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
34889 {
34890 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",67);
34891 }
34892 }
34893
34894 if(!p_iputw(guysbuf[i].firesfx,f))
34895 {
34896 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",68);
34897 }
34898 //misc 16->32
34899 for (int q=0; q < 17; ++q)
34900 {
34901 if (!p_iputl(guysbuf[i].attributes[15 + q], f))
34902 {
34903 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 69 + q);
34904 }
34905 }
34906 for ( int32_t q = 0; q < 32; q++ )
34907 {
34908 if(!p_iputl(guysbuf[i].movement[q],f))
34909 {
34910 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",86);
34911 }
34912 }
34913 for ( int32_t q = 0; q < 32; q++ )
34914 {
34915 if(!p_iputl(guysbuf[i].new_weapon[q],f))
34916 {
34917 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",87);
34918 }
34919 }
34920 if(!p_iputw(guysbuf[i].script,f))
34921 {
34922 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",88);
34923 }
34924 for ( int32_t q = 0; q < 8; q++ )
34925 {
34926 if(!p_iputl(guysbuf[i].initD[q],f))
34927 {
34928 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",89);
34929 }
34930 }
34931 if(!p_iputl(guysbuf[i].editorflags,f))
34932 {
34933 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",91);
34934 }
34935 //misc 13-15
34936 for (int q = 0; q < 4; ++q)
34937 {
34938 if (!p_iputl(guysbuf[i].attributes[12 + q], f))
34939 {
34940 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d", 92 + q);
34941 }
34942 }
34943
34944 //Enemy Editor InitD[] labels
34945 for ( int32_t q = 0; q < 8; q++ )
34946 {
34947 for ( int32_t w = 0; w < 65; w++ )
34948 {
34949 if(!p_putc(guysbuf[i].initD_label[q][w],f))
34950 {
34951 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",95);
34952 }
34953 }
34954 for ( int32_t w = 0; w < 65; w++ )
34955 {
34956 if(!p_putc(guysbuf[i].weapon_initD_label[q][w],f))
34957 {
34958 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",96);
34959 }
34960 }
34961 }
34962 if(!p_iputw(guysbuf[i].weaponscript,f))
34963 {
34964 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",97);
34965 }
34966 //eweapon initD
34967 for ( int32_t q = 0; q < 8; q++ )
34968 {
34969 if(!p_iputl(guysbuf[i].weap_initiald[q],f))
34970 {
34971 Z_scripterrlog("do_savegamestructs FAILED to write GUY NODE: %d",98);
34972 }
34973 }
34974
34975 }
34976 }
34977
34978
34979 void FFScript::write_items(PACKFILE *f, int32_t vers_id)
34980 {
34981 for(int32_t i=0; i<MAXITEMS; i++)
34982 {
34983 if(!p_iputl(itemsbuf[i].tile,f))
34984 {
34985 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",6);
34986 }
34987
34988 if(!p_putc(itemsbuf[i].misc_flags,f))
34989 {
34990 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",7);
34991 }
34992
34993 if(!p_putc(itemsbuf[i].csets,f))
34994 {
34995 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",8);
34996 }
34997
34998 if(!p_putc(itemsbuf[i].frames,f))
34999 {
35000 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",9);
35001 }
35002
35003 if(!p_putc(itemsbuf[i].speed,f))
35004 {
35005 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",10);
35006 }
35007
35008 if(!p_putc(itemsbuf[i].delay,f))
35009 {
35010 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",11);
35011 }
35012
35013 if(!p_iputl(itemsbuf[i].ltm,f))
35014 {
35015 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",12);
35016 }
35017
35018 if(!p_iputl(itemsbuf[i].family,f))
35019 {
35020 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",13);
35021 }
35022
35023 if(!p_putc(itemsbuf[i].fam_type,f))
35024 {
35025 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",14);
35026 }
35027
35028 if(!p_iputl(itemsbuf[i].power,f))
35029 {
35030 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",14);
35031 }
35032
35033 if(!p_iputl(itemsbuf[i].flags,f))
35034 {
35035 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",15);
35036 }
35037
35038 if(!p_iputw(itemsbuf[i].script,f))
35039 {
35040 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",16);
35041 }
35042
35043 if(!p_putc(itemsbuf[i].count,f))
35044 {
35045 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",17);
35046 }
35047
35048 if(!p_iputw(itemsbuf[i].amount,f))
35049 {
35050 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",18);
35051 }
35052
35053 if(!p_iputw(itemsbuf[i].collect_script,f))
35054 {
35055 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",19);
35056 }
35057
35058 if(!p_iputw(itemsbuf[i].setmax,f))
35059 {
35060 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",21);
35061 }
35062
35063 if(!p_iputw(itemsbuf[i].max,f))
35064 {
35065 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",22);
35066 }
35067
35068 if(!p_putc(itemsbuf[i].playsound,f))
35069 {
35070 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",23);
35071 }
35072
35073 for(int32_t j=0; j<8; j++)
35074 {
35075 if(!p_iputl(itemsbuf[i].initiald[j],f))
35076 {
35077 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",24);
35078 }
35079 }
35080
35081 if(!p_putc(itemsbuf[i].wpn,f))
35082 {
35083 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",26);
35084 }
35085
35086 if(!p_putc(itemsbuf[i].wpn2,f))
35087 {
35088 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",27);
35089 }
35090
35091 if(!p_putc(itemsbuf[i].wpn3,f))
35092 {
35093 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",28);
35094 }
35095
35096 if(!p_putc(itemsbuf[i].wpn4,f))
35097 {
35098 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",29);
35099 }
35100
35101 if(!p_putc(itemsbuf[i].wpn5,f))
35102 {
35103 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",30);
35104 }
35105
35106 if(!p_putc(itemsbuf[i].wpn6,f))
35107 {
35108 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",31);
35109 }
35110
35111 if(!p_putc(itemsbuf[i].wpn7,f))
35112 {
35113 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",32);
35114 }
35115
35116 if(!p_putc(itemsbuf[i].wpn8,f))
35117 {
35118 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",33);
35119 }
35120
35121 if(!p_putc(itemsbuf[i].wpn9,f))
35122 {
35123 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",34);
35124 }
35125
35126 if(!p_putc(itemsbuf[i].wpn10,f))
35127 {
35128 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",35);
35129 }
35130
35131 if(!p_putc(itemsbuf[i].pickup_hearts,f))
35132 {
35133 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",36);
35134 }
35135
35136 if(!p_iputl(itemsbuf[i].misc1,f))
35137 {
35138 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",37);
35139 }
35140
35141 if(!p_iputl(itemsbuf[i].misc2,f))
35142 {
35143 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",38);
35144 }
35145
35146 if(!p_putc(itemsbuf[i].cost_amount[0],f))
35147 {
35148 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",39);
35149 }
35150
35151 if(!p_iputl(itemsbuf[i].misc3,f))
35152 {
35153 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",40);
35154 }
35155
35156 if(!p_iputl(itemsbuf[i].misc4,f))
35157 {
35158 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",41);
35159 }
35160
35161 if(!p_iputl(itemsbuf[i].misc5,f))
35162 {
35163 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",42);
35164 }
35165
35166 if(!p_iputl(itemsbuf[i].misc6,f))
35167 {
35168 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",43);
35169 }
35170
35171 if(!p_iputl(itemsbuf[i].misc7,f))
35172 {
35173 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",44);
35174 }
35175
35176 if(!p_iputl(itemsbuf[i].misc8,f))
35177 {
35178 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",45);
35179 }
35180
35181 if(!p_iputl(itemsbuf[i].misc9,f))
35182 {
35183 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",46);
35184 }
35185
35186 if(!p_iputl(itemsbuf[i].misc10,f))
35187 {
35188 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",47);
35189 }
35190
35191 if(!p_putc(itemsbuf[i].usesound,f))
35192 {
35193 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",48);
35194 }
35195
35196 if(!p_putc(itemsbuf[i].usesound2,f))
35197 {
35198 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",48);
35199 }
35200
35201 //New itemdata vars -Z
35202 //! version 27
35203
35204 if(!p_putc(itemsbuf[i].useweapon,f))
35205 {
35206 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",49);
35207 }
35208 if(!p_putc(itemsbuf[i].usedefense,f))
35209 {
35210 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",50);
35211 }
35212 if(!p_iputl(itemsbuf[i].weaprange,f))
35213 {
35214 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",51);
35215 }
35216 if(!p_iputl(itemsbuf[i].weapduration,f))
35217 {
35218 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",52);
35219 }
35220 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
35221 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
35222 {
35223 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",53);
35224 }
35225 }
35226 //version 28
35227 if(!p_iputl(itemsbuf[i].duplicates,f))
35228 {
35229 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",54);
35230 }
35231 for ( int32_t q = 0; q < INITIAL_D; q++ )
35232 {
35233 if(!p_iputl(itemsbuf[i].weap_initiald[q],f))
35234 {
35235 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",55);
35236 }
35237 }
35238
35239 if(!p_putc(itemsbuf[i].drawlayer,f))
35240 {
35241 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",57);
35242 }
35243
35244
35245 if(!p_iputl(itemsbuf[i].hxofs,f))
35246 {
35247 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",58);
35248 }
35249 if(!p_iputl(itemsbuf[i].hyofs,f))
35250 {
35251 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",59);
35252 }
35253 if(!p_iputl(itemsbuf[i].hxsz,f))
35254 {
35255 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",60);
35256 }
35257 if(!p_iputl(itemsbuf[i].hysz,f))
35258 {
35259 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",61);
35260 }
35261 if(!p_iputl(itemsbuf[i].hzsz,f))
35262 {
35263 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",62);
35264 }
35265 if(!p_iputl(itemsbuf[i].xofs,f))
35266 {
35267 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",63);
35268 }
35269 if(!p_iputl(itemsbuf[i].yofs,f))
35270 {
35271 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",64);
35272 }
35273 if(!p_iputl(itemsbuf[i].weap_hxofs,f))
35274 {
35275 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",65);
35276 }
35277 if(!p_iputl(itemsbuf[i].weap_hyofs,f))
35278 {
35279 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",66);
35280 }
35281 if(!p_iputl(itemsbuf[i].weap_hxsz,f))
35282 {
35283 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",67);
35284 }
35285 if(!p_iputl(itemsbuf[i].weap_hysz,f))
35286 {
35287 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",68);
35288 }
35289 if(!p_iputl(itemsbuf[i].weap_hzsz,f))
35290 {
35291 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",69);
35292 }
35293 if(!p_iputl(itemsbuf[i].weap_xofs,f))
35294 {
35295 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",70);
35296 }
35297 if(!p_iputl(itemsbuf[i].weap_yofs,f))
35298 {
35299 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",71);
35300 }
35301 if(!p_iputw(itemsbuf[i].weaponscript,f))
35302 {
35303 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",72);
35304 }
35305 if(!p_iputl(itemsbuf[i].wpnsprite,f))
35306 {
35307 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",73);
35308 }
35309 if(!p_iputl(itemsbuf[i].magiccosttimer[0],f))
35310 {
35311 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",74);
35312 }
35313 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
35314 {
35315 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",75);
35316 }
35317 if(!p_iputl(itemsbuf[i].tilew,f))
35318 {
35319 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",76);
35320 }
35321 if(!p_iputl(itemsbuf[i].tileh,f))
35322 {
35323 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",77);
35324 }
35325 if(!p_iputl(itemsbuf[i].weapoverrideFLAGS,f))
35326 {
35327 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",78);
35328 }
35329 if(!p_iputl(itemsbuf[i].weap_tilew,f))
35330 {
35331 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",79);
35332 }
35333 if(!p_iputl(itemsbuf[i].weap_tileh,f))
35334 {
35335 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",80);
35336 }
35337 if(!p_iputl(itemsbuf[i].pickup,f))
35338 {
35339 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",81);
35340 }
35341 if(!p_iputw(itemsbuf[i].pstring,f))
35342 {
35343 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",82);
35344 }
35345 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
35346 {
35347 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",83);
35348 }
35349
35350 if(!p_putc(itemsbuf[i].cost_counter[0],f))
35351 {
35352 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",84);
35353 }
35354
35355 //InitD[] labels
35356 for ( int32_t q = 0; q < 8; q++ )
35357 {
35358 for ( int32_t w = 0; w < 65; w++ )
35359 {
35360 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
35361 {
35362 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",85);
35363 }
35364 }
35365 for ( int32_t w = 0; w < 65; w++ )
35366 {
35367 if(!p_putc(itemsbuf[i].weapon_initD_label[q][w],f))
35368 {
35369 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",86);
35370 }
35371 }
35372 for ( int32_t w = 0; w < 65; w++ )
35373 {
35374 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
35375 {
35376 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",87);
35377 }
35378 }
35379 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
35380 {
35381 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",88);
35382 }
35383 }
35384
35385 if(!p_iputw(itemsbuf[i].sprite_script,f))
35386 {
35387 Z_scripterrlog("do_savegamestructs FAILED to read ITEM NODE: %d",90);
35388 }
35389
35390
35391 }
35392 }
35393
35394 void FFScript::read_items(PACKFILE *f, int32_t vers_id)
35395 {
35396 for(int32_t i=0; i<MAXITEMS; i++)
35397 {
35398 if(!p_igetl(&itemsbuf[i].tile,f))
35399 {
35400 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",6);
35401 }
35402
35403 if(!p_getc(&itemsbuf[i].misc_flags,f))
35404 {
35405 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",7);
35406 }
35407
35408 if(!p_getc(&itemsbuf[i].csets,f))
35409 {
35410 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",8);
35411 }
35412
35413 if(!p_getc(&itemsbuf[i].frames,f))
35414 {
35415 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",9);
35416 }
35417
35418 if(!p_getc(&itemsbuf[i].speed,f))
35419 {
35420 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",10);
35421 }
35422
35423 if(!p_getc(&itemsbuf[i].delay,f))
35424 {
35425 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",11);
35426 }
35427
35428 if(!p_igetl(&itemsbuf[i].ltm,f))
35429 {
35430 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",12);
35431 }
35432
35433 if(!p_igetl(&itemsbuf[i].family,f))
35434 {
35435 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",13);
35436 }
35437
35438 if(!p_getc(&itemsbuf[i].fam_type,f))
35439 {
35440 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",14);
35441 }
35442
35443 if(!p_igetl(&itemsbuf[i].power,f))
35444 {
35445 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",14);
35446 }
35447
35448 if(!p_igetl(&itemsbuf[i].flags,f))
35449 {
35450 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",15);
35451 }
35452
35453 if(!p_igetw(&itemsbuf[i].script,f))
35454 {
35455 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",16);
35456 }
35457
35458 if(!p_getc(&itemsbuf[i].count,f))
35459 {
35460 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",17);
35461 }
35462
35463 if(!p_igetw(&itemsbuf[i].amount,f))
35464 {
35465 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",18);
35466 }
35467
35468 if(!p_igetw(&itemsbuf[i].collect_script,f))
35469 {
35470 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",19);
35471 }
35472
35473 if(!p_igetw(&itemsbuf[i].setmax,f))
35474 {
35475 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",21);
35476 }
35477
35478 if(!p_igetw(&itemsbuf[i].max,f))
35479 {
35480 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",22);
35481 }
35482
35483 if(!p_getc(&itemsbuf[i].playsound,f))
35484 {
35485 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",23);
35486 }
35487
35488 for(int32_t j=0; j<8; j++)
35489 {
35490 if(!p_igetl(&itemsbuf[i].initiald[j],f))
35491 {
35492 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",24);
35493 }
35494 }
35495
35496 if(!p_getc(&itemsbuf[i].wpn,f))
35497 {
35498 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",26);
35499 }
35500
35501 if(!p_getc(&itemsbuf[i].wpn2,f))
35502 {
35503 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",27);
35504 }
35505
35506 if(!p_getc(&itemsbuf[i].wpn3,f))
35507 {
35508 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",28);
35509 }
35510
35511 if(!p_getc(&itemsbuf[i].wpn4,f))
35512 {
35513 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",29);
35514 }
35515
35516 if(!p_getc(&itemsbuf[i].wpn5,f))
35517 {
35518 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",30);
35519 }
35520
35521 if(!p_getc(&itemsbuf[i].wpn6,f))
35522 {
35523 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",31);
35524 }
35525
35526 if(!p_getc(&itemsbuf[i].wpn7,f))
35527 {
35528 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",32);
35529 }
35530
35531 if(!p_getc(&itemsbuf[i].wpn8,f))
35532 {
35533 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",33);
35534 }
35535
35536 if(!p_getc(&itemsbuf[i].wpn9,f))
35537 {
35538 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",34);
35539 }
35540
35541 if(!p_getc(&itemsbuf[i].wpn10,f))
35542 {
35543 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",35);
35544 }
35545
35546 if(!p_getc(&itemsbuf[i].pickup_hearts,f))
35547 {
35548 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",36);
35549 }
35550
35551 if(!p_igetl(&itemsbuf[i].misc1,f))
35552 {
35553 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",37);
35554 }
35555
35556 if(!p_igetl(&itemsbuf[i].misc2,f))
35557 {
35558 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",38);
35559 }
35560
35561 if(!p_getc(&itemsbuf[i].cost_amount[0],f))
35562 {
35563 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",39);
35564 }
35565
35566 if(!p_igetl(&itemsbuf[i].misc3,f))
35567 {
35568 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",40);
35569 }
35570
35571 if(!p_igetl(&itemsbuf[i].misc4,f))
35572 {
35573 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",41);
35574 }
35575
35576 if(!p_igetl(&itemsbuf[i].misc5,f))
35577 {
35578 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",42);
35579 }
35580
35581 if(!p_igetl(&itemsbuf[i].misc6,f))
35582 {
35583 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",43);
35584 }
35585
35586 if(!p_igetl(&itemsbuf[i].misc7,f))
35587 {
35588 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",44);
35589 }
35590
35591 if(!p_igetl(&itemsbuf[i].misc8,f))
35592 {
35593 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",45);
35594 }
35595
35596 if(!p_igetl(&itemsbuf[i].misc9,f))
35597 {
35598 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",46);
35599 }
35600
35601 if(!p_igetl(&itemsbuf[i].misc10,f))
35602 {
35603 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",47);
35604 }
35605
35606 if(!p_getc(&itemsbuf[i].usesound,f))
35607 {
35608 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",48);
35609 }
35610
35611 if(!p_getc(&itemsbuf[i].usesound2,f))
35612 {
35613 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",48);
35614 }
35615
35616 //New itemdata vars -Z
35617 //! version 27
35618
35619 if(!p_getc(&itemsbuf[i].useweapon,f))
35620 {
35621 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",49);
35622 }
35623 if(!p_getc(&itemsbuf[i].usedefense,f))
35624 {
35625 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",50);
35626 }
35627 if(!p_igetl(&itemsbuf[i].weaprange,f))
35628 {
35629 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",51);
35630 }
35631 if(!p_igetl(&itemsbuf[i].weapduration,f))
35632 {
35633 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",52);
35634 }
35635 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
35636 if(!p_igetl(&itemsbuf[i].weap_pattern[q],f))
35637 {
35638 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",53);
35639 }
35640 }
35641 //version 28
35642 if(!p_igetl(&itemsbuf[i].duplicates,f))
35643 {
35644 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",54);
35645 }
35646 for ( int32_t q = 0; q < INITIAL_D; q++ )
35647 {
35648 if(!p_igetl(&itemsbuf[i].weap_initiald[q],f))
35649 {
35650 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",55);
35651 }
35652 }
35653
35654 if(!p_getc(&itemsbuf[i].drawlayer,f))
35655 {
35656 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",57);
35657 }
35658
35659
35660 if(!p_igetl(&itemsbuf[i].hxofs,f))
35661 {
35662 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",58);
35663 }
35664 if(!p_igetl(&itemsbuf[i].hyofs,f))
35665 {
35666 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",59);
35667 }
35668 if(!p_igetl(&itemsbuf[i].hxsz,f))
35669 {
35670 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",60);
35671 }
35672 if(!p_igetl(&itemsbuf[i].hysz,f))
35673 {
35674 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",61);
35675 }
35676 if(!p_igetl(&itemsbuf[i].hzsz,f))
35677 {
35678 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",62);
35679 }
35680 if(!p_igetl(&itemsbuf[i].xofs,f))
35681 {
35682 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",63);
35683 }
35684 if(!p_igetl(&itemsbuf[i].yofs,f))
35685 {
35686 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",64);
35687 }
35688 if(!p_igetl(&itemsbuf[i].weap_hxofs,f))
35689 {
35690 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",65);
35691 }
35692 if(!p_igetl(&itemsbuf[i].weap_hyofs,f))
35693 {
35694 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",66);
35695 }
35696 if(!p_igetl(&itemsbuf[i].weap_hxsz,f))
35697 {
35698 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",67);
35699 }
35700 if(!p_igetl(&itemsbuf[i].weap_hysz,f))
35701 {
35702 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",68);
35703 }
35704 if(!p_igetl(&itemsbuf[i].weap_hzsz,f))
35705 {
35706 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",69);
35707 }
35708 if(!p_igetl(&itemsbuf[i].weap_xofs,f))
35709 {
35710 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",70);
35711 }
35712 if(!p_igetl(&itemsbuf[i].weap_yofs,f))
35713 {
35714 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",71);
35715 }
35716 if(!p_igetw(&itemsbuf[i].weaponscript,f))
35717 {
35718 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",72);
35719 }
35720 if(!p_igetl(&itemsbuf[i].wpnsprite,f))
35721 {
35722 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",73);
35723 }
35724 if(!p_igetl(&itemsbuf[i].magiccosttimer[0],f))
35725 {
35726 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",74);
35727 }
35728 if(!p_igetl(&itemsbuf[i].overrideFLAGS,f))
35729 {
35730 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",75);
35731 }
35732 if(!p_igetl(&itemsbuf[i].tilew,f))
35733 {
35734 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",76);
35735 }
35736 if(!p_igetl(&itemsbuf[i].tileh,f))
35737 {
35738 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",77);
35739 }
35740 if(!p_igetl(&itemsbuf[i].weapoverrideFLAGS,f))
35741 {
35742 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",78);
35743 }
35744 if(!p_igetl(&itemsbuf[i].weap_tilew,f))
35745 {
35746 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",79);
35747 }
35748 if(!p_igetl(&itemsbuf[i].weap_tileh,f))
35749 {
35750 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",80);
35751 }
35752 if(!p_igetl(&itemsbuf[i].pickup,f))
35753 {
35754 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",81);
35755 }
35756 if(!p_igetw(&itemsbuf[i].pstring,f))
35757 {
35758 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",82);
35759 }
35760 if(!p_igetw(&itemsbuf[i].pickup_string_flags,f))
35761 {
35762 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",83);
35763 }
35764
35765 if(!p_getc(&itemsbuf[i].cost_counter[0],f))
35766 {
35767 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",84);
35768 }
35769
35770 //InitD[] labels
35771 for ( int32_t q = 0; q < 8; q++ )
35772 {
35773 for ( int32_t w = 0; w < 65; w++ )
35774 {
35775 if(!p_getc(&itemsbuf[i].initD_label[q][w],f))
35776 {
35777 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",85);
35778 }
35779 }
35780 for ( int32_t w = 0; w < 65; w++ )
35781 {
35782 if(!p_getc(&itemsbuf[i].weapon_initD_label[q][w],f))
35783 {
35784 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",86);
35785 }
35786 }
35787 for ( int32_t w = 0; w < 65; w++ )
35788 {
35789 if(!p_getc(&itemsbuf[i].sprite_initD_label[q][w],f))
35790 {
35791 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",87);
35792 }
35793 }
35794 if(!p_igetl(&itemsbuf[i].sprite_initiald[q],f))
35795 {
35796 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",88);
35797 }
35798 }
35799
35800 if(!p_igetw(&itemsbuf[i].sprite_script,f))
35801 {
35802 Z_scripterrlog("do_savegamestructs FAILED to write ITEM NODE: %d",90);
35803 }
35804
35805
35806 }
35807 }
35808
35809 void FFScript::write_mapscreens(PACKFILE *f,int32_t vers_id)
35810 {
35811
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 310 times.
310 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
35812 {
35813
2/2
✓ Branch 0 taken 42160 times.
✓ Branch 1 taken 310 times.
42470 for(int32_t j=0; j<MAPSCRS; j++)
35814 {
35815 42160 mapscr *m = &TheMaps[i*MAPSCRS+j];
35816
35817
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->valid,f))
35818 {
35819 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35820 }
35821
35822
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->guy,f))
35823 {
35824 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35825 }
35826
35827 {
35828
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_iputw(m->str,f))
35829 {
35830 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35831 }
35832 }
35833
35834
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->room,f))
35835 {
35836 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35837 }
35838
35839
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->item,f))
35840 {
35841 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35842 }
35843
35844
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->hasitem, f))
35845 {
35846 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35847 }
35848
35849
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
35850 {
35851
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168640 times.
168640 if(!p_putc(m->tilewarptype[k],f))
35852 {
35853 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35854 }
35855 168640 }
35856
35857
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_iputw(m->door_combo_set,f))
35858 {
35859 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35860 }
35861
35862
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
35863 {
35864
1/2
✓ Branch 0 taken 168640 times.
✗ Branch 1 not taken.
168640 if(!p_putc(m->warpreturnx[k],f))
35865 {
35866 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35867 }
35868 168640 }
35869
35870
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
35871 {
35872
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168640 times.
168640 if(!p_putc(m->warpreturny[k],f))
35873 {
35874 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35875 }
35876 168640 }
35877
35878
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_iputw(m->warpreturnc,f))
35879 {
35880 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35881 }
35882
35883
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->stairx,f))
35884 {
35885 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35886 }
35887
35888
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->stairy,f))
35889 {
35890 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35891 }
35892
35893
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->itemx,f))
35894 {
35895 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35896 }
35897
35898
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->itemy,f))
35899 {
35900 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35901 }
35902
35903
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputw(m->color,f))
35904 {
35905 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35906 }
35907
35908
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->flags11,f))
35909 {
35910 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35911 }
35912
35913
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
35914 {
35915
1/2
✓ Branch 0 taken 168640 times.
✗ Branch 1 not taken.
168640 if(!p_putc(m->door[k],f))
35916 {
35917 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35918 }
35919 168640 }
35920
35921
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
35922 {
35923
1/2
✓ Branch 0 taken 168640 times.
✗ Branch 1 not taken.
168640 if(!p_iputw(m->tilewarpdmap[k],f))
35924 {
35925 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35926 }
35927 168640 }
35928
35929
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
35930 {
35931
1/2
✓ Branch 0 taken 168640 times.
✗ Branch 1 not taken.
168640 if(!p_putc(m->tilewarpscr[k],f))
35932 {
35933 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35934 }
35935 168640 }
35936
35937
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->tilewarpoverlayflags,f))
35938 {
35939 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35940 }
35941
35942
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->exitdir,f))
35943 {
35944 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35945 }
35946
35947
2/2
✓ Branch 0 taken 421600 times.
✓ Branch 1 taken 42160 times.
463760 for(int32_t k=0; k<10; k++)
35948 {
35949 {
35950
1/2
✓ Branch 0 taken 421600 times.
✗ Branch 1 not taken.
421600 if(!p_iputw(m->enemy[k],f))
35951 {
35952 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35953 }
35954 }
35955 421600 }
35956
35957
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->pattern,f))
35958 {
35959 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35960 }
35961
35962
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
35963 {
35964
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168640 times.
168640 if(!p_putc(m->sidewarptype[k],f))
35965 {
35966 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35967 }
35968 168640 }
35969
35970
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->sidewarpoverlayflags,f))
35971 {
35972 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35973 }
35974
35975
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->warparrivalx,f))
35976 {
35977 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35978 }
35979
35980
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->warparrivaly,f))
35981 {
35982 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35983 }
35984
35985
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
35986 {
35987
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168640 times.
168640 if(!p_putc(m->path[k],f))
35988 {
35989 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35990 }
35991 168640 }
35992
35993
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
35994 {
35995
1/2
✓ Branch 0 taken 168640 times.
✗ Branch 1 not taken.
168640 if(!p_putc(m->sidewarpscr[k],f))
35996 {
35997 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
35998 }
35999 168640 }
36000
36001
2/2
✓ Branch 0 taken 168640 times.
✓ Branch 1 taken 42160 times.
210800 for(int32_t k=0; k<4; k++)
36002 {
36003
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168640 times.
168640 if(!p_iputw(m->sidewarpdmap[k],f))
36004 {
36005 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36006 }
36007 168640 }
36008
36009
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->sidewarpindex,f))
36010 {
36011 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36012 }
36013
36014
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputw(m->undercombo,f))
36015 {
36016 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36017 }
36018
36019
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->undercset,f))
36020 {
36021 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36022 }
36023
36024
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputw(m->catchall,f))
36025 {
36026 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36027 }
36028
36029
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags,f))
36030 {
36031 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36032 }
36033
36034
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags2,f))
36035 {
36036 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36037 }
36038
36039
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags3,f))
36040 {
36041 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36042 }
36043
36044
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->flags4,f))
36045 {
36046 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36047 }
36048
36049
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags5,f))
36050 {
36051 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36052 }
36053
36054
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputw(m->noreset,f))
36055 {
36056 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36057 }
36058
36059
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputw(m->nocarry,f))
36060 {
36061 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36062 }
36063
36064
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->flags6,f))
36065 {
36066 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36067 }
36068
36069
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags7,f))
36070 {
36071 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36072 }
36073
36074
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->flags8,f))
36075 {
36076 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36077 }
36078
36079
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->flags9,f))
36080 {
36081 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36082 }
36083
36084
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->flags10,f))
36085 {
36086 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36087 }
36088
36089
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->csensitive,f))
36090 {
36091 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36092 }
36093
36094
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->oceansfx,f))
36095 {
36096 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36097 }
36098
36099
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->bosssfx,f))
36100 {
36101 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36102 }
36103
36104
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->secretsfx,f))
36105 {
36106 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36107 }
36108
36109
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->holdupsfx,f))
36110 {
36111 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36112 }
36113
36114
2/2
✓ Branch 0 taken 252960 times.
✓ Branch 1 taken 42160 times.
295120 for(int32_t k=0; k<6; k++)
36115 {
36116
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252960 times.
252960 if(!p_putc(m->layermap[k],f))
36117 {
36118 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36119 }
36120 252960 }
36121
36122
2/2
✓ Branch 0 taken 252960 times.
✓ Branch 1 taken 42160 times.
295120 for(int32_t k=0; k<6; k++)
36123 {
36124
1/2
✓ Branch 0 taken 252960 times.
✗ Branch 1 not taken.
252960 if(!p_putc(m->layerscreen[k],f))
36125 {
36126 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36127 }
36128 252960 }
36129
36130
2/2
✓ Branch 0 taken 252960 times.
✓ Branch 1 taken 42160 times.
295120 for(int32_t k=0; k<6; k++)
36131 {
36132
1/2
✓ Branch 0 taken 252960 times.
✗ Branch 1 not taken.
252960 if(!p_putc(m->layeropacity[k],f))
36133 {
36134 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36135 }
36136 252960 }
36137
36138
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_iputw(m->timedwarptics,f))
36139 {
36140 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36141 }
36142
36143
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->nextmap,f))
36144 {
36145 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36146 }
36147
36148
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->nextscr,f))
36149 {
36150 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36151 }
36152
36153
2/2
✓ Branch 0 taken 5396480 times.
✓ Branch 1 taken 42160 times.
5438640 for(int32_t k=0; k<128; k++)
36154 {
36155
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5396480 times.
5396480 if(!p_iputw(m->secretcombo[k],f))
36156 {
36157 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36158 }
36159 5396480 }
36160
36161
2/2
✓ Branch 0 taken 5396480 times.
✓ Branch 1 taken 42160 times.
5438640 for(int32_t k=0; k<128; k++)
36162 {
36163
1/2
✓ Branch 0 taken 5396480 times.
✗ Branch 1 not taken.
5396480 if(!p_putc(m->secretcset[k],f))
36164 {
36165 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36166 }
36167 5396480 }
36168
36169
2/2
✓ Branch 0 taken 5396480 times.
✓ Branch 1 taken 42160 times.
5438640 for(int32_t k=0; k<128; k++)
36170 {
36171
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5396480 times.
5396480 if(!p_putc(m->secretflag[k],f))
36172 {
36173 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36174 }
36175 5396480 }
36176
36177
2/2
✓ Branch 0 taken 7420160 times.
✓ Branch 1 taken 42160 times.
7462320 for(int32_t k=0; k<176; k++)
36178 {
36179 try
36180 {
36181
2/4
✓ Branch 0 taken 7420160 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7420160 times.
7420160 if(!p_iputw(m->data[k],f))
36182 {
36183 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36184 }
36185
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
7420160 }
36186 catch(std::out_of_range& )
36187 {
36188 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36189 }
36190 7420160 }
36191
36192
2/2
✓ Branch 0 taken 7420160 times.
✓ Branch 1 taken 42160 times.
7462320 for(int32_t k=0; k<176; k++)
36193 {
36194 try
36195 {
36196
2/4
✓ Branch 0 taken 7420160 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7420160 times.
7420160 if(!p_putc(m->sflag[k], f))
36197 {
36198 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36199 }
36200
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
7420160 }
36201 catch(std::out_of_range& )
36202 {
36203 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36204 }
36205 7420160 }
36206
36207
2/2
✓ Branch 0 taken 7420160 times.
✓ Branch 1 taken 42160 times.
7462320 for(int32_t k=0; k<176; k++)
36208 {
36209 try
36210 {
36211
2/4
✓ Branch 0 taken 7420160 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7420160 times.
7420160 if(!p_putc(m->cset[k],f))
36212 {
36213 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36214 }
36215
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
7420160 }
36216 catch(std::out_of_range& )
36217 {
36218 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36219 }
36220 7420160 }
36221
36222
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_iputw(m->screen_midi,f))
36223 {
36224 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36225 }
36226
36227
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_putc(m->lens_layer,f))
36228 {
36229 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36230 }
36231
36232 42160 m->ensureFFC(32);
36233
2/2
✓ Branch 0 taken 1349120 times.
✓ Branch 1 taken 42160 times.
1391280 for(int32_t k=0; k<32; k++)
36234 {
36235 1349120 ffcdata& ffc = m->ffcs[k];
36236
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputw(ffc.data,f))
36237 {
36238 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36239 }
36240
36241
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_putc(ffc.cset,f))
36242 {
36243 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36244 }
36245
36246
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputw(ffc.delay,f))
36247 {
36248 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36249 }
36250
36251
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputzf(ffc.x,f))
36252 {
36253 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36254 }
36255
36256
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputzf(ffc.y,f))
36257 {
36258 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36259 }
36260
36261
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputzf(ffc.vx,f))
36262 {
36263 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36264 }
36265
36266
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputzf(ffc.vy,f))
36267 {
36268 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36269 }
36270
36271
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputzf(ffc.ax,f))
36272 {
36273 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36274 }
36275
36276
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputzf(ffc.ay,f))
36277 {
36278 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36279 }
36280
36281
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_putc(ffc.link,f))
36282 {
36283 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36284 }
36285
36286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputl(ffc.hit_width,f))
36287 {
36288 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36289 }
36290
36291
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputl(ffc.hit_height,f))
36292 {
36293 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36294 }
36295
36296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_putc(ffc.txsz,f))
36297 {
36298 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36299 }
36300
36301
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_putc(ffc.tysz,f))
36302 {
36303 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36304 }
36305
36306
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputl(ffc.flags,f))
36307 {
36308 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36309 }
36310
36311
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputw(ffc.script,f))
36312 {
36313 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36314 }
36315
36316
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[0],f))
36317 {
36318 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36319 }
36320
36321
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[1],f))
36322 {
36323 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36324 }
36325
36326
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputl(ffc.initd[2],f))
36327 {
36328 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36329 }
36330
36331
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1349120 times.
1349120 if(!p_iputl(ffc.initd[3],f))
36332 {
36333 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36334 }
36335
36336
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[4],f))
36337 {
36338 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36339 }
36340
36341
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[5],f))
36342 {
36343 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36344 }
36345
36346
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[6],f))
36347 {
36348 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36349 }
36350
36351
1/2
✓ Branch 0 taken 1349120 times.
✗ Branch 1 not taken.
1349120 if(!p_iputl(ffc.initd[7],f))
36352 {
36353 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36354 }
36355
36356 1349120 }
36357
36358
1/2
✓ Branch 0 taken 42160 times.
✗ Branch 1 not taken.
42160 if(!p_iputw(m->script,f))
36359 {
36360 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36361 }
36362
2/2
✓ Branch 0 taken 337280 times.
✓ Branch 1 taken 42160 times.
379440 for ( int32_t q = 0; q < 8; q++ )
36363 {
36364
1/2
✓ Branch 0 taken 337280 times.
✗ Branch 1 not taken.
337280 if(!p_iputl(m->screeninitd[q],f))
36365 {
36366 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36367 }
36368
36369 337280 }
36370
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->preloadscript,f))
36371 {
36372 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36373 }
36374
36375
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->hidelayers,f))
36376 {
36377 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36378 }
36379
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42160 times.
42160 if(!p_putc(m->hidescriptlayers,f))
36380 {
36381 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODEz\n"); return;
36382 }
36383
36384
36385 42160 } //end mapscr for loop
36386 310 }
36387 }
36388 void FFScript::read_mapscreens(PACKFILE *f,int32_t vers_id)
36389 {
36390 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
36391 {
36392 for(int32_t j=0; j<MAPSCRS; j++)
36393 {
36394 mapscr *m = &TheMaps[i*MAPSCRS+j];
36395
36396 if(!p_getc(&(m->valid),f))
36397 {
36398 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36399 }
36400
36401 if(!p_getc(&(m->guy),f))
36402 {
36403 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36404 }
36405
36406 {
36407 if(!p_igetw(&(m->str),f))
36408 {
36409 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36410 }
36411 }
36412
36413 if(!p_getc(&(m->room),f))
36414 {
36415 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36416 }
36417
36418 if(!p_getc(&(m->item),f))
36419 {
36420 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36421 }
36422
36423 if(!p_getc(&(m->hasitem), f))
36424 {
36425 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36426 }
36427
36428 for(int32_t k=0; k<4; k++)
36429 {
36430 if(!p_getc(&(m->tilewarptype[k]),f))
36431 {
36432 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36433 }
36434 }
36435
36436 if(!p_igetw(&(m->door_combo_set),f))
36437 {
36438 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36439 }
36440
36441 for(int32_t k=0; k<4; k++)
36442 {
36443 if(!p_getc(&(m->warpreturnx[k]),f))
36444 {
36445 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36446 }
36447 }
36448
36449 for(int32_t k=0; k<4; k++)
36450 {
36451 if(!p_getc(&(m->warpreturny[k]),f))
36452 {
36453 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36454 }
36455 }
36456
36457 if(!p_igetw(&(m->warpreturnc),f))
36458 {
36459 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36460 }
36461
36462 if(!p_getc(&(m->stairx),f))
36463 {
36464 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36465 }
36466
36467 if(!p_getc(&(m->stairy),f))
36468 {
36469 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36470 }
36471
36472 if(!p_getc(&(m->itemx),f))
36473 {
36474 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36475 }
36476
36477 if(!p_getc(&(m->itemy),f))
36478 {
36479 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36480 }
36481
36482 if(!p_igetw(&(m->color),f))
36483 {
36484 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36485 }
36486
36487 if(!p_getc(&(m->flags11),f))
36488 {
36489 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36490 }
36491
36492 for(int32_t k=0; k<4; k++)
36493 {
36494 if(!p_getc(&(m->door[k]),f))
36495 {
36496 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36497 }
36498 }
36499
36500 for(int32_t k=0; k<4; k++)
36501 {
36502 if(!p_igetw(&(m->tilewarpdmap[k]),f))
36503 {
36504 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36505 }
36506 }
36507
36508 for(int32_t k=0; k<4; k++)
36509 {
36510 if(!p_getc(&(m->tilewarpscr[k]),f))
36511 {
36512 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36513 }
36514 }
36515
36516 if(!p_getc(&(m->tilewarpoverlayflags),f))
36517 {
36518 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36519 }
36520
36521 if(!p_getc(&(m->exitdir),f))
36522 {
36523 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36524 }
36525
36526 for(int32_t k=0; k<10; k++)
36527 {
36528 {
36529 if(!p_igetw(&(m->enemy[k]),f))
36530 {
36531 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36532 }
36533 }
36534 }
36535
36536 if(!p_getc(&(m->pattern),f))
36537 {
36538 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36539 }
36540
36541 for(int32_t k=0; k<4; k++)
36542 {
36543 if(!p_getc(&(m->sidewarptype[k]),f))
36544 {
36545 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36546 }
36547 }
36548
36549 if(!p_getc(&(m->sidewarpoverlayflags),f))
36550 {
36551 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36552 }
36553
36554 if(!p_getc(&(m->warparrivalx),f))
36555 {
36556 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36557 }
36558
36559 if(!p_getc(&(m->warparrivaly),f))
36560 {
36561 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36562 }
36563
36564 for(int32_t k=0; k<4; k++)
36565 {
36566 if(!p_getc(&(m->path[k]),f))
36567 {
36568 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36569 }
36570 }
36571
36572 for(int32_t k=0; k<4; k++)
36573 {
36574 if(!p_getc(&(m->sidewarpscr[k]),f))
36575 {
36576 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36577 }
36578 }
36579
36580 for(int32_t k=0; k<4; k++)
36581 {
36582 if(!p_igetw(&(m->sidewarpdmap[k]),f))
36583 {
36584 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36585 }
36586 }
36587
36588 if(!p_getc(&(m->sidewarpindex),f))
36589 {
36590 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36591 }
36592
36593 if(!p_igetw(&(m->undercombo),f))
36594 {
36595 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36596 }
36597
36598 if(!p_getc(&(m->undercset),f))
36599 {
36600 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36601 }
36602
36603 if(!p_igetw(&(m->catchall),f))
36604 {
36605 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36606 }
36607
36608 if(!p_getc(&(m->flags),f))
36609 {
36610 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36611 }
36612
36613 if(!p_getc(&(m->flags2),f))
36614 {
36615 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36616 }
36617
36618 if(!p_getc(&(m->flags3),f))
36619 {
36620 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36621 }
36622
36623 if(!p_getc(&(m->flags4),f))
36624 {
36625 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36626 }
36627
36628 if(!p_getc(&(m->flags5),f))
36629 {
36630 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36631 }
36632
36633 if(!p_igetw(&(m->noreset),f))
36634 {
36635 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36636 }
36637
36638 if(!p_igetw(&(m->nocarry),f))
36639 {
36640 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36641 }
36642
36643 if(!p_getc(&(m->flags6),f))
36644 {
36645 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36646 }
36647
36648 if(!p_getc(&(m->flags7),f))
36649 {
36650 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36651 }
36652
36653 if(!p_getc(&(m->flags8),f))
36654 {
36655 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36656 }
36657
36658 if(!p_getc(&(m->flags9),f))
36659 {
36660 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36661 }
36662
36663 if(!p_getc(&(m->flags10),f))
36664 {
36665 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36666 }
36667
36668 if(!p_getc(&(m->csensitive),f))
36669 {
36670 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36671 }
36672
36673 if(!p_getc(&(m->oceansfx),f))
36674 {
36675 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36676 }
36677
36678 if(!p_getc(&(m->bosssfx),f))
36679 {
36680 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36681 }
36682
36683 if(!p_getc(&(m->secretsfx),f))
36684 {
36685 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36686 }
36687
36688 if(!p_getc(&(m->holdupsfx),f))
36689 {
36690 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36691 }
36692
36693 for(int32_t k=0; k<6; k++)
36694 {
36695 if(!p_getc(&(m->layermap[k]),f))
36696 {
36697 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36698 }
36699 }
36700
36701 for(int32_t k=0; k<6; k++)
36702 {
36703 if(!p_getc(&(m->layerscreen[k]),f))
36704 {
36705 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36706 }
36707 }
36708
36709 for(int32_t k=0; k<6; k++)
36710 {
36711 if(!p_getc(&(m->layeropacity[k]),f))
36712 {
36713 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36714 }
36715 }
36716
36717 if(!p_igetw(&(m->timedwarptics),f))
36718 {
36719 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36720 }
36721
36722 if(!p_getc(&(m->nextmap),f))
36723 {
36724 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36725 }
36726
36727 if(!p_getc(&(m->nextscr),f))
36728 {
36729 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36730 }
36731
36732 for(int32_t k=0; k<128; k++)
36733 {
36734 if(!p_igetw(&(m->secretcombo[k]),f))
36735 {
36736 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36737 }
36738 }
36739
36740 for(int32_t k=0; k<128; k++)
36741 {
36742 if(!p_getc(&(m->secretcset[k]),f))
36743 {
36744 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36745 }
36746 }
36747
36748 for(int32_t k=0; k<128; k++)
36749 {
36750 if(!p_getc(&(m->secretflag[k]),f))
36751 {
36752 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36753 }
36754 }
36755
36756 for(int32_t k=0; k<176; k++)
36757 {
36758 try
36759 {
36760 if(!p_igetw(&(m->data[k]),f))
36761 {
36762 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36763 }
36764 }
36765 catch(std::out_of_range& )
36766 {
36767 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36768 }
36769 }
36770
36771 for(int32_t k=0; k<176; k++)
36772 {
36773 try
36774 {
36775 if(!p_getc(&(m->sflag[k]),f))
36776 {
36777 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36778 }
36779 }
36780 catch(std::out_of_range& )
36781 {
36782 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36783 }
36784 }
36785
36786 for(int32_t k=0; k<176; k++)
36787 {
36788 try
36789 {
36790 if(!p_getc(&(m->cset[k]),f))
36791 {
36792 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36793 }
36794 }
36795 catch(std::out_of_range& )
36796 {
36797 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36798 }
36799 }
36800
36801 if(!p_igetw(&(m->screen_midi),f))
36802 {
36803 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36804 }
36805
36806 if(!p_getc(&(m->lens_layer),f))
36807 {
36808 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36809 }
36810
36811 m->ensureFFC(32);
36812 word tempw;
36813 for(int32_t k=0; k<32; k++)
36814 {
36815 ffcdata& ffc = m->ffcs[k];
36816 if(!p_igetw(&tempw,f))
36817 {
36818 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36819 }
36820 zc_ffc_set(ffc, tempw);
36821
36822 if(!p_getc(&(ffc.cset),f))
36823 {
36824 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36825 }
36826
36827 if(!p_igetw(&(ffc.delay),f))
36828 {
36829 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36830 }
36831
36832 if(!p_igetzf(&(ffc.x),f))
36833 {
36834 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36835 }
36836
36837 if(!p_igetzf(&(ffc.y),f))
36838 {
36839 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36840 }
36841
36842 if(!p_igetzf(&(ffc.vx),f))
36843 {
36844 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36845 }
36846
36847 if(!p_igetzf(&(ffc.vy),f))
36848 {
36849 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36850 }
36851
36852 if(!p_igetzf(&(ffc.ax),f))
36853 {
36854 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36855 }
36856
36857 if(!p_igetzf(&(ffc.ay),f))
36858 {
36859 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36860 }
36861
36862 if(!p_getc(&(ffc.link),f))
36863 {
36864 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36865 }
36866
36867 if(!p_igetl(&(ffc.hit_width),f))
36868 {
36869 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36870 }
36871
36872 if(!p_igetl(&(ffc.hit_height),f))
36873 {
36874 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36875 }
36876
36877 if(!p_getc(&(ffc.txsz),f))
36878 {
36879 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36880 }
36881
36882 if(!p_getc(&(ffc.tysz),f))
36883 {
36884 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36885 }
36886
36887 if(!p_igetl(&(ffc.flags),f))
36888 {
36889 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36890 }
36891
36892 if(!p_igetw(&(ffc.script),f))
36893 {
36894 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36895 }
36896
36897 if(!p_igetl(&(ffc.initd[0]),f))
36898 {
36899 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36900 }
36901
36902 if(!p_igetl(&(ffc.initd[1]),f))
36903 {
36904 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36905 }
36906
36907 if(!p_igetl(&(ffc.initd[2]),f))
36908 {
36909 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36910 }
36911
36912 if(!p_igetl(&(ffc.initd[3]),f))
36913 {
36914 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36915 }
36916
36917 if(!p_igetl(&(ffc.initd[4]),f))
36918 {
36919 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36920 }
36921
36922 if(!p_igetl(&(ffc.initd[5]),f))
36923 {
36924 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36925 }
36926
36927 if(!p_igetl(&(ffc.initd[6]),f))
36928 {
36929 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36930 }
36931
36932 if(!p_igetl(&(ffc.initd[7]),f))
36933 {
36934 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36935 }
36936
36937 }
36938
36939 if(!p_igetw(&(m->script),f))
36940 {
36941 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36942 }
36943 for ( int32_t q = 0; q < 8; q++ )
36944 {
36945 if(!p_igetl(&(m->screeninitd[q]),f))
36946 {
36947 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36948 }
36949
36950 }
36951 if(!p_getc(&(m->preloadscript),f))
36952 {
36953 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36954 }
36955
36956 if ( vers_id >= 2 )
36957 {
36958 if(!p_getc(&(m->hidelayers),f))
36959 {
36960 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36961 }
36962 if(!p_getc(&(m->hidescriptlayers),f))
36963 {
36964 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE\n"); return;
36965 }
36966
36967 }
36968
36969
36970 }//end mapscr all for loop
36971
36972 }
36973 }
36974 /*
36975 void FFScript::write_maps(PACKFILE *f, int32_t vers_id)
36976 {
36977 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
36978 {
36979 for(int32_t j=0; j<MAPSCRS; j++)
36980 {
36981 if ( !(FFCore.write_mapscreen(f,i,j,vers_id)) )
36982 {
36983 Z_scripterrlog("do_savegamestructs FAILED to write MAPSCR NODE: %d",i*j);
36984 }
36985 }
36986 }
36987 }
36988
36989 void FFScript::read_maps(PACKFILE *f, int32_t vers_id)
36990 {
36991 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
36992 {
36993 for(int32_t j=0; j<MAPSCRS; j++)
36994 {
36995 if ( !(FFCore.read_mapscreen(f,i,j,vers_id)) )
36996 {
36997 Z_scripterrlog("do_savegamestructs FAILED to read MAPSCR NODE: %d",i*j);
36998 }
36999 }
37000 }
37001 }
37002 */
37003
37004
37005 int32_t FFScript::getHeroOTile(int32_t index1, int32_t index2)
37006 {
37007 {
37008 herospritetype lst = (herospritetype)index1;
37009 int32_t dir = index2;
37010 int32_t the_ret = 0;
37011 switch(lst)
37012 {
37013 case LSprwalkspr: the_ret = walkspr[dir][0]; break;
37014 case LSprstabspr: the_ret = stabspr[dir][0]; break;
37015 case LSprslashspr: the_ret = slashspr[dir][0]; break;
37016 case LSprrevslashspr: the_ret = revslashspr[dir][0]; break;
37017 case LSprfloatspr: the_ret = floatspr[dir][0]; break;
37018 case LSprswimspr: the_ret = swimspr[dir][0]; break;
37019 case LSprdivespr: the_ret = divespr[dir][0]; break;
37020 case LSprdrownspr: the_ret = drowningspr[dir][0]; break;
37021 case LSprsidedrownspr: the_ret = sidedrowningspr[dir][0]; break;
37022 case LSprlavadrownspr: the_ret = drowning_lavaspr[dir][0]; break;
37023 case LSprsideswimspr: the_ret = sideswimspr[dir][0]; break;
37024 case LSprsideswimslashspr: the_ret = sideswimslashspr[dir][0]; break;
37025 case LSprsideswimstabspr: the_ret = sideswimstabspr[dir][0]; break;
37026 case LSprsideswimpoundspr: the_ret = sideswimpoundspr[dir][0]; break;
37027 case LSprsideswimchargespr: the_ret = sideswimchargespr[dir][0]; break;
37028 case LSprpoundspr: the_ret = poundspr[dir][0]; break;
37029 case LSprjumpspr: the_ret = jumpspr[dir][0]; break;
37030 case LSprchargespr: the_ret = chargespr[dir][0]; break;
37031 case LSprcastingspr: the_ret = castingspr[0]; break;
37032 case LSprsideswimcastingspr: the_ret = sideswimcastingspr[0]; break;
37033 case LSprholdspr1: the_ret = holdspr[0][0][0]; break;
37034 case LSprholdspr2: the_ret = holdspr[0][1][0]; break;
37035 case LSprholdsprw1: the_ret = holdspr[1][0][0]; break;
37036 case LSprholdsprw2: the_ret = holdspr[1][1][0]; break;
37037 case LSprholdsprSw1: the_ret = sideswimholdspr[0][0]; break;
37038 case LSprholdsprSw2: the_ret = sideswimholdspr[1][0]; break;
37039 default: the_ret = 0;
37040 }
37041
37042 return the_ret*10000;
37043 }
37044 }
37045
37046 defWpnSprite FFScript::getDefWeaponSprite(int32_t wpnid)
37047 {
37048 switch(wpnid)
37049 {
37050 case wNone: return ws_0;
37051 case wSword: return ws_0;
37052 case wBeam: return wsBeam;
37053 case wBrang : return wsBrang;
37054 case wBomb: return wsBomb;
37055 case wSBomb: return wsSBomb;
37056 case wLitBomb: return wsBombblast;
37057 case wLitSBomb: return wsBombblast;
37058 case wArrow: return wsArrow;
37059 case wRefArrow: return wsArrow;
37060 case wFire: return wsFire;
37061 case wRefFire: return wsFire;
37062 case wRefFire2: return wsFire;
37063 case wWhistle: return wsUnused45;
37064 case wBait: return wsBait;
37065 case wWand: return wsWandHandle;
37066 case wMagic: return wsMagic;
37067 case wCatching: return wsUnused45;
37068 case wWind: return wsWind;
37069 case wRefMagic: return wsRefMagic;
37070 case wRefFireball: return wsRefFireball;
37071 case wRefRock: return wsRock;
37072 case wHammer: return wsHammer;
37073 case wHookshot: return wsHookshotHead;
37074 case wHSHandle: return wsHookshotHandle;
37075 case wHSChain: return wsHookshotChainH;
37076 case wSSparkle: return wsSilverSparkle;
37077 case wFSparkle: return wsGoldSparkle;
37078 case wSmack: return wsHammerSmack;
37079 case wPhantom: return wsUnused45;
37080 case wCByrna: return wsByrnaCane;
37081 case wRefBeam: return wsRefBeam;
37082 case wStomp: return wsUnused45;
37083 case lwMax: return wsUnused45;
37084 case wScript1:
37085 case wScript2:
37086 case wScript3:
37087 case wScript4:
37088 case wScript5:
37089 case wScript6:
37090 case wScript7:
37091 case wScript8:
37092 case wScript9:
37093 case wScript10: return ws_0;
37094 case wIce: return wsIce; //new
37095 case wFlame: return wsEFire2; //new
37096 //not implemented; t/b/a
37097 case wSound:
37098 case wThrown:
37099 case wPot:
37100 case wLit:
37101 case wBombos:
37102 case wEther:
37103 case wQuake:
37104 case wSword180:
37105 case wSwordLA: return wsUnused45;
37106
37107 case ewFireball: return wsFireball2;
37108 case ewArrow: return wsEArrow;
37109 case ewBrang: return wsBrang;
37110 case ewSword: return wsEBeam;
37111 case ewRock: return wsRock;
37112 case ewMagic: return wsEMagic;
37113 case ewBomb: return wsEBomb;
37114 case ewSBomb: return wsESbomb;
37115 case ewLitBomb: return wsEBombblast;
37116 case ewLitSBomb: return wsESbombblast;
37117 case ewFireTrail: return wsEFiretrail;
37118 case ewFlame: return wsEFire;
37119 case ewWind: return wsEWind;
37120 case ewFlame2: return wsEFire2;
37121 case ewFlame2Trail: return wsEFiretrail2;
37122 case ewIce: return wsIce;
37123 case ewFireball2: return wsFireball2;
37124 default: return wsUnused45;
37125 }
37126 };
37127
37128 598 void FFScript::do_loadlweapon_by_script_uid(const bool v)
37129 {
37130 598 int32_t uid = SH::get_arg(sarg1, v);
37131
1/2
✓ Branch 0 taken 598 times.
✗ Branch 1 not taken.
598 if (ResolveLWeapon_checkSpriteList(uid))
37132 598 ri->lwpn = uid;
37133 else
37134 {
37135 ri->lwpn = 0;
37136 }
37137 598 }
37138
37139 void FFScript::do_loadeweapon_by_script_uid(const bool v)
37140 {
37141 int32_t uid = SH::get_arg(sarg1, v);
37142 if (ResolveEWeapon_checkSpriteList(uid))
37143 ri->ewpn = uid;
37144 else
37145 {
37146 ri->ewpn = 0;
37147 }
37148 }
37149
37150
37151 12 void FFScript::do_loadnpc_by_script_uid(const bool v)
37152 {
37153 12 int32_t uid = SH::get_arg(sarg1, v);
37154
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (ResolveSprite<enemy>(uid, "enemy"))
37155 12 ri->guyref = uid;
37156 else
37157 {
37158 ri->guyref = 0;
37159 }
37160 12 }
37161
37162 //Combo Scripts
37163
37164 98064 void FFScript::clear_combo_scripts()
37165 {
37166 98064 combo_id_cache.clear();
37167 98064 combo_id_cache.resize(region_num_rpos * 7);
37168 98064 std::fill(combo_id_cache.begin(), combo_id_cache.end(), -1);
37169 98064 FFCore.deallocateAllScriptOwnedOfType(ScriptType::Combo);
37170 98064 FFCore.clear_script_engine_data_of_type(ScriptType::Combo);
37171 98064 }
37172
37173 8189 void FFScript::clear_combo_script(const rpos_handle_t& rpos_handle)
37174 {
37175 8189 int32_t index = get_combopos_ref(rpos_handle);
37176 8189 combo_id_cache[index] = -1;
37177 8189 combopos_modified = index;
37178 8189 clear_script_engine_data(ScriptType::Combo, index);
37179 8189 }
37180
37181 3713016 int32_t FFScript::combo_script_engine(const bool preload, const bool waitdraw)
37182 {
37183 bool enabled[7];
37184
2/2
✓ Branch 0 taken 25991112 times.
✓ Branch 1 taken 3713016 times.
29704128 for (int32_t q = 0; q < 7; ++q)
37185 {
37186 25991112 enabled[q] = get_qr(qr_COMBOSCRIPTS_LAYER_0 + q);
37187 25991112 }
37188
37189 3713016 auto& combo_cache = combo_caches::script;
37190
37191 ///non-scripted effects
37192 2357169528 for_every_rpos([&](const rpos_handle_t& rpos_handle) {
37193
2/2
✓ Branch 0 taken 860970528 times.
✓ Branch 1 taken 1492485984 times.
2353456512 if (!enabled[rpos_handle.layer])
37194 1492485984 return;
37195
37196 860970528 int32_t combopos_ref = get_combopos_ref(rpos_handle);
37197 860970528 word cid = rpos_handle.data();
37198
2/2
✓ Branch 0 taken 859854151 times.
✓ Branch 1 taken 1116377 times.
860970528 if(combo_id_cache[combopos_ref] != cid)
37199 {
37200 1116377 combopos_modified = combopos_ref;
37201 1116377 combo_id_cache[combopos_ref] = cid;
37202 1116377 clear_script_engine_data(ScriptType::Combo, combopos_ref);
37203 1116377 }
37204
37205 860970528 auto script = combo_cache.minis[cid].script;
37206
2/2
✓ Branch 0 taken 852378798 times.
✓ Branch 1 taken 8591730 times.
860970528 if (script)
37207 {
37208 8591730 auto& data = get_script_engine_data(ScriptType::Combo, combopos_ref);
37209
2/2
✓ Branch 0 taken 7870889 times.
✓ Branch 1 taken 720841 times.
8591730 if (data.doscript)
37210 {
37211
4/4
✓ Branch 0 taken 356612 times.
✓ Branch 1 taken 364229 times.
✓ Branch 2 taken 352329 times.
✓ Branch 3 taken 4283 times.
720841 if (waitdraw && !data.waitdraw) return; //waitdraw not set
37212
37213 368512 ZScriptVersion::RunScript(ScriptType::Combo, script, combopos_ref);
37214
2/2
✓ Branch 0 taken 364229 times.
✓ Branch 1 taken 4283 times.
368512 if (waitdraw) data.waitdraw = true;
37215 368512 }
37216 8239401 }
37217 2353456512 });
37218
37219 3713016 return 1;
37220 }
37221
37222 792477 int32_t FFScript::Distance(double x1, double y1, double x2, double y2)
37223 {
37224 792477 double x = (x1-x2);
37225 792477 double y = (y1-y2);
37226 792477 double sum = (x*x)+(y*y);
37227 //if(((int32_t)sum) < 0)
37228 //{
37229 // Z_scripterrlog("Distance() attempted to calculate square root of %ld!\n", ((int32_t)sum));
37230 // return -10000;;
37231 //}
37232 792477 sum *= 1000000.0;
37233 792477 double total = sqrt(sum)*10;
37234 792477 return int32_t(total);
37235 }
37236
37237 int32_t FFScript::Distance(double x1, double y1, double x2, double y2, int32_t scale)
37238 {
37239 double x3 = x1+(x2-x1)/scale;
37240 double y3 = y1+(y2-y1)/scale;
37241 //double sum = (x*x)+(y*y);
37242 //if(((int32_t)sum) < 0)
37243 //{
37244 // Z_scripterrlog("Distance() attempted to calculate square root of %ld!\n", ((int32_t)sum));
37245 // return -10000;
37246 //}
37247 //sum *= 1000000.0;
37248 //double total = sqrt(sum)*10;
37249 //return int32_t(total*scale);
37250 return (FFCore.Distance(x1, y1, x3, y3)*scale);
37251 }
37252
37253 int32_t FFScript::LongDistance(double x1, double y1, double x2, double y2)
37254 {
37255 double x = (x1-x2);
37256 double y = (y1-y2);
37257 double sum = (x*x)+(y*y);
37258 //if(((int32_t)sum) < 0)
37259 //{
37260 // Z_scripterrlog("Distance() attempted to calculate square root of %ld!\n", ((int32_t)sum));
37261 // return -10000;;
37262 //}
37263 double total = sqrt(sum);
37264 return int32_t(total);
37265 }
37266
37267 int32_t FFScript::LongDistance(double x1, double y1, double x2, double y2, int32_t scale)
37268 {
37269 double x3 = x1+(x2-x1)/scale;
37270 double y3 = y1+(y2-y1)/scale;
37271 //double sum = (x*x)+(y*y);
37272 //if(((int32_t)sum) < 0)
37273 //{
37274 // Z_scripterrlog("Distance() attempted to calculate square root of %ld!\n", ((int32_t)sum));
37275 // return -10000;
37276 //}
37277 //sum *= 1000000.0;
37278 //double total = sqrt(sum)*10;
37279 //return int32_t(total*scale);
37280 return (FFCore.LongDistance(x1, y1, x3, y3)*scale);
37281 }
37282
37283 353155924 bool command_is_wait(int command)
37284 {
37285
2/2
✓ Branch 0 taken 353030073 times.
✓ Branch 1 taken 125851 times.
353155924 switch (command)
37286 {
37287 case WAITFRAME:
37288 case WAITDRAW:
37289 case WAITTO:
37290 case WAITEVENT:
37291 case WAITFRAMESR:
37292 125851 return true;
37293 }
37294 353030073 return false;
37295 353155924 }
37296
37297 228667717 bool command_is_goto(int command)
37298 {
37299 // GOTOR/return ops left out on purpose.
37300
2/2
✓ Branch 0 taken 211813802 times.
✓ Branch 1 taken 16853915 times.
228667717 switch (command)
37301 {
37302 case GOTO:
37303 case GOTOCMP:
37304 case GOTOLESS:
37305 case GOTOMORE:
37306 case GOTOTRUE:
37307 case GOTOFALSE:
37308 16853915 return true;
37309 }
37310 211813802 return false;
37311 228667717 }
37312
37313 130366010 bool command_uses_comparison_result(int command)
37314 {
37315
2/2
✓ Branch 0 taken 125601336 times.
✓ Branch 1 taken 4764674 times.
130366010 switch (command)
37316 {
37317 case GOTOTRUE:
37318 case GOTOFALSE:
37319 case GOTOMORE:
37320 case GOTOLESS:
37321 case GOTOCMP:
37322 case SETCMP:
37323 case SETTRUE:
37324 case SETTRUEI:
37325 case SETFALSE:
37326 case SETFALSEI:
37327 case SETMOREI:
37328 case SETLESSI:
37329 case SETMORE:
37330 case SETLESS:
37331 case STACKWRITEATVV_IF:
37332 4764674 return true;
37333 }
37334 125601336 return false;
37335 130366010 }
37336
37337 195164841 bool command_writes_comparison_result(int command)
37338 {
37339
2/2
✓ Branch 0 taken 187065028 times.
✓ Branch 1 taken 8099813 times.
195164841 switch (command)
37340 {
37341 case SETCMP:
37342 case SETTRUE:
37343 case SETTRUEI:
37344 case SETFALSE:
37345 case SETFALSEI:
37346 case SETMOREI:
37347 case SETLESSI:
37348 case SETMORE:
37349 case SETLESS:
37350 8099813 return true;
37351 }
37352 187065028 return false;
37353 195164841 }
37354
37355 12928200 int command_to_cmp(int command, int arg)
37356 {
37357
12/14
✓ Branch 0 taken 1713546 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3259497 times.
✓ Branch 3 taken 4132 times.
✓ Branch 4 taken 79429 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3125697 times.
✓ Branch 7 taken 1424903 times.
✓ Branch 8 taken 1843141 times.
✓ Branch 9 taken 776203 times.
✓ Branch 10 taken 426891 times.
✓ Branch 11 taken 52189 times.
✓ Branch 12 taken 185284 times.
✓ Branch 13 taken 37288 times.
12928200 switch (command)
37358 {
37359 case SETCMP:
37360 case GOTOCMP:
37361 1713546 return arg;
37362
37363 case GOTOTRUE:
37364 3259497 return CMP_EQ;
37365 case GOTOFALSE:
37366 4132 return CMP_NE;
37367 case GOTOMORE:
37368 79429 return CMP_GE;
37369 case GOTOLESS:
37370 return get_qr(qr_GOTOLESSNOTEQUAL) ? CMP_LE : CMP_LT;
37371
37372 case SETTRUE:
37373 3125697 return CMP_EQ;
37374 case SETFALSE:
37375 1424903 return CMP_NE;
37376 case SETMORE:
37377 1843141 return CMP_GE;
37378 case SETLESS:
37379 776203 return CMP_LE;
37380
37381 case SETTRUEI:
37382 426891 return CMP_SETI|CMP_EQ;
37383 case SETFALSEI:
37384 52189 return CMP_SETI|CMP_NE;
37385 case SETMOREI:
37386 185284 return CMP_SETI|CMP_GE;
37387 case SETLESSI:
37388 37288 return CMP_SETI|CMP_LE;
37389 }
37390
37391 ASSERT(false);
37392 return 0;
37393 12928200 }
37394
37395 1345825 bool command_could_return_not_ok(int command)
37396 {
37397
2/2
✓ Branch 0 taken 1338707 times.
✓ Branch 1 taken 7118 times.
1345825 switch (command)
37398 {
37399 case 0xFFFF:
37400 case EWPNDEL:
37401 case GAMECONTINUE:
37402 case GAMEEND:
37403 case GAMEEXIT:
37404 case GAMERELOAD:
37405 case GAMESAVECONTINUE:
37406 case GAMESAVEQUIT:
37407 case ITEMDEL:
37408 case LWPNDEL:
37409 case NPCKICKBUCKET:
37410 7118 return true;
37411 }
37412 1338707 return false;
37413 1345825 }
37414
37415 167130320 bool command_is_pure(int command)
37416 {
37417
2/2
✓ Branch 0 taken 115837170 times.
✓ Branch 1 taken 51293150 times.
167130320 switch (command)
37418 {
37419 case ABS:
37420 case ADDR:
37421 case ADDV:
37422 case ANDR:
37423 case ANDR32:
37424 case ANDV:
37425 case ANDV32:
37426 case ARCCOSR:
37427 case ARCCOSV:
37428 case ARCSINR:
37429 case ARCSINV:
37430 case BITNOT:
37431 case BITNOT32:
37432 case CASTBOOLF:
37433 case CEILING:
37434 case COMPAREV2:
37435 case COSR:
37436 case COSV:
37437 case DIVV2:
37438 case FACTORIAL:
37439 case FLOOR:
37440 case IPOWERR:
37441 case IPOWERV:
37442 case ISALLOCATEDBITMAP:
37443 case LOAD:
37444 case LOADD:
37445 case LOADI:
37446 case LOG10:
37447 case LOGE:
37448 case LSHIFTR:
37449 case LSHIFTR32:
37450 case LSHIFTV:
37451 case LSHIFTV32:
37452 case MAXR:
37453 case MAXV:
37454 case MAXVARG:
37455 case MINR:
37456 case MINV:
37457 case MINVARG:
37458 case MODR:
37459 case MODV:
37460 case MODV2:
37461 case NANDR:
37462 case NANDV:
37463 case NORR:
37464 case NORV:
37465 case NOT:
37466 case ORR:
37467 case ORR32:
37468 case ORV:
37469 case ORV32:
37470 case PEEK:
37471 case PEEKATV:
37472 case POWERR:
37473 case POWERV:
37474 case ROUND:
37475 case ROUNDAWAY:
37476 case RSHIFTR:
37477 case RSHIFTR32:
37478 case RSHIFTV:
37479 case RSHIFTV32:
37480 case SETCMP:
37481 case SETFALSE:
37482 case SETFALSEI:
37483 case SETLESS:
37484 case SETLESSI:
37485 case SETMORE:
37486 case SETMOREI:
37487 case SETR:
37488 case SETTRUE:
37489 case SETTRUEI:
37490 case SETV:
37491 case SINR:
37492 case SINV:
37493 case SUBR:
37494 case SUBV:
37495 case SUBV2:
37496 case TANR:
37497 case TANV:
37498 case TOBYTE:
37499 case TOINTEGER:
37500 case TOSHORT:
37501 case TOSIGNEDBYTE:
37502 case TOWORD:
37503 case TRUNCATE:
37504 case XNORR:
37505 case XNORV:
37506 case XORR:
37507 case XORR32:
37508 case XORV:
37509 case XORV32:
37510 51293150 return true;
37511 }
37512
37513 115837170 return false;
37514 167130320 }
37515
37516 860991071 int32_t get_combopos_ref(const rpos_handle_t& rpos_handle)
37517 {
37518 860991071 return rpos_handle.layer * region_num_rpos + (int)rpos_handle.rpos;
37519 }
37520
37521 int32_t get_combopos_ref(rpos_t rpos, int32_t layer)
37522 {
37523 return layer * region_num_rpos + (int)rpos;
37524 }
37525
37526 649434 rpos_t combopos_ref_to_rpos(int32_t combopos_ref)
37527 {
37528 649434 return (rpos_t)(combopos_ref % region_num_rpos);
37529 }
37530
37531 387550 int32_t combopos_ref_to_layer(int32_t combopos_ref)
37532 {
37533 387550 return combopos_ref / region_num_rpos;
37534 }
37535
37536 ScriptEngineData& get_ffc_script_engine_data(int index)
37537 {
37538 return get_script_engine_data(ScriptType::FFC, index);
37539 }
37540
37541 1638734 ScriptEngineData& get_item_script_engine_data(int index)
37542 {
37543 1638734 return get_script_engine_data(ScriptType::Item, index);
37544 }
37545